CreateUser Method for Entity Framework MVC3 Razor Custom Member Provider C# Using LINQ

From my C# MVC3 Razor Custom Membership Provider article and source code, here is the code for the CreateUser method. I welcome any suggestions for improvement.
public override MembershipUser CreateUser(string username, string password,
    string email, string passwordQuestion, string passwordAnswer,
    bool isApproved, object providerUserKey, out MembershipCreateStatus status)
    // only first 3 fields are passed in from the AccountModels.cs
        status = UsernameExists(username);
        if (status == MembershipCreateStatus.DuplicateUserName)
            return null;
        status = DuplicateEmail(email);
        if (status == MembershipCreateStatus.DuplicateEmail)
            return null;

        byte[] hashedPassword = HashPassword(password.Trim());
        GetValues gv = new GetValues();
        string ipAddress = gv.getIPAddress();
        int userStatus = 

        using (var context = new SSSEntities())
            UserProfile newUser = new UserProfile()
                Email = email,
                UserPassword = hashedPassword,
                UserName = username,
                DateCreated = DateTime.Now,
                DateUpdated = DateTime.Now,
                DatePasswordLastChanged = DateTime.Now,
                DateLastLogin = DateTime.Now,
                UserStatusCode = userStatus,
                IpAddress = ipAddress,

            // insert the User Role
            int userRole = 
            // look up the desired user role : 
            // uses a UserRole join table with a many to many relation
            // between the UserProfile table and the ListValue table
            ListValue ur = context.ListValues
                .SingleOrDefault(lv => lv.ListValueId == userRole);


            // NKT: after creation, go back and retrieve the auto-generated identity key and 
            // update the userId's for the created and updated userId
            int userId = newUser.UserId;
            newUser.CreatedUserId = userId;
            newUser.UpdatedUserId = userId;

            status = MembershipCreateStatus.Success;
            return GetMembershipUser(newUser);
    catch (ArgumentException)
        status = MembershipCreateStatus.ProviderError;
        return null;



No Comments