Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeDevelopment and...Development and...DNN Platform (o...DNN Platform (o...Programmatically creating user and adding to role with DNN APIProgrammatically creating user and adding to role with DNN API
Previous
 
Next
New Post
6/25/2015 11:30 AM
 
Jonathan Opperman wrote:

Thanks Cathal. I did come across that but I'm not very familiar with VB, however, looking at it again I  am able to surmise that it first creates the user, then grabs the userID which is used to add the user to the role if the user creation was successful. I'll try it out... hopefully I can adapt that in C# and the way I have to implement this.  

I don't mean to be a pain but I really hope DNN improves on their API documentation...the most recent only displays the namespaces, no examples. DNN is a great framework from what I have seen but where is MVC, RECENT module development tutorials and ORM support? In terms of Visual Studio templates I've only found very old extensions. Being, albeit extended, family of Microsoft I would have thought DNN development would be a lot smoother and perhaps with even more best practice orientated methodologies. Hope to see that change. 

I agree with your complaint about the API documentation, we do document when we add new code, but there is a legacy of 10+ years of no/badly documented code. We welcome contributions to the documentation (no jira required) via pull requests - http://www.dnnsoftware.com/wiki/github . As mentioned the problem is primarily age of codebase, when we create DNN neXt, one of the mandatory requirements is fully documented (and unit testable) code

As for templates, https://christoctemplate.codeplex.com/ is the popular (and well maintained) choice.

Finally, regarding MVC etc., see the quick start for items that are coming in DNN 8 http://www.dnnsoftware.com/wiki/dnn-8...


Buy the new Professional DNN7: Open Source .NET CMS Platform book Amazon US
 
New Post
6/25/2015 11:31 AM
 
Jonathan Opperman wrote:

Came right with this:

AddRole method:

public bool addRoleToUser(UserInfo user, string roleName, DateTime expiry)

        {

       bool rc = false;

       RoleInfo newRole = roleController.GetRoleByName(user.PortalID, roleName);

       if (newRole != null && user != null)

       {

       rc = user.IsInRole(roleName);

                roleController.AddUserRole(user.PortalID, user.UserID, newRole.RoleID, DateTime.MinValue, expiry);

       

       user = UserController.GetUserById(user.PortalID, user.UserID);

       rc = user.IsInRole(roleName);

       }

       return rc;

        }

Create user and add to role:

private void ApproveFor(WholesaleClient client)

        {

            client.IsVerified = true;

            var userInfo = GenerateUserInfo(client);

            var createStatus = membershipProvider.CreateUser(ref userInfo);

 

            if (createStatus == UserCreateStatus.InvalidPassword)

                throw new Exception("Invalid password");

 

            //save back to table with IsVerified set

            if (createStatus == UserCreateStatus.Success)

            {

                var roleName = "Wholesale Client";

                addRoleToUser(userInfo, roleName, DateTime.MaxValue);

                clientRepository.Update(client);

                return;   

            }

 

            throw new Exception("Error occurred");

 

        }

 Glad to hear you got it working - i'll add a link to your forum post in the wiki so the next time someone has the same requirement they don't have to do so much work


Buy the new Professional DNN7: Open Source .NET CMS Platform book Amazon US
 
New Post
6/30/2015 2:15 AM
 

That sounds promising. I'm certainly looking forward to DNN 8!

 
Previous
 
Next
HomeHomeDevelopment and...Development and...DNN Platform (o...DNN Platform (o...Programmatically creating user and adding to role with DNN APIProgrammatically creating user and adding to role with DNN API


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out