public async Task<IdentityResult> RegisterUser(UserModel userModel) { ApplicationUser user = new ApplicationUser(); try { user = new ApplicationUser { UserName = userModel.Email, Email = userModel.Email, TwoFactorEnabled = true//, //PhoneNumber = userModel.MobilePhoneNumber }; IdentityResult result = await UserManager.CreateAsync(user, userModel.Password); if (result.Succeeded) { var roleresult = UserManager.AddToRole(user.Id, RoleType.NonClient); //if (string.IsNullOrEmpty(userModel.SSN)) // userModel.SSN = null; using (WW_DevEntities context = new WW_DevEntities()) { Client model = new Client { Id = Guid.NewGuid(), AspUserId = user.Id, FirstName = ProperCase.Convert(userModel.FirstName), LastName = ProperCase.Convert(userModel.LastName), MiddleName = ProperCase.Convert(userModel.MiddleName), Suffix = ProperCase.Convert(userModel.Suffix), //Gender = userModel.Gender, //SSN = userModel.SSN, //DateOfBirth = userModel.DateOfBirth, CreatedDate = DateTime.Now }; context.Clients.Add(model); context.PasswordHistories.Add(new PasswordHistory { CreatedDate = DateTime.Now, HashPassword = Hash.Get(userModel.Password), UserID = user.Id }); //ClientPhone mPhone = new ClientPhone(); //ClientPhone wPhone = new ClientPhone(); //ClientPhone hPhone = new ClientPhone(); //if (userModel.MobilePhoneNumber != null) //{ // mPhone.PhoneNumber = userModel.MobilePhoneNumber; // mPhone.CreatedDate = DateTime.Now; // context.ClientPhones.Add(mPhone); //} //if (userModel.WorkPhoneNumber != null) //{ // wPhone.PhoneNumber = userModel.WorkPhoneNumber; // wPhone.CreatedDate = DateTime.Now; // context.ClientPhones.Add(wPhone); //} //if (userModel.HomePhoneNumber != null) //{ // hPhone.PhoneNumber = userModel.HomePhoneNumber; // hPhone.CreatedDate = DateTime.Now; // context.ClientPhones.Add(hPhone); //} await context.SaveChangesAsync(); //if (userModel.MobilePhoneNumber != null) //{ // context.ClientPhoneAssociatives.Add(new ClientPhoneAssociative() // { // Id = model.Id, // ClientPhoneId = mPhone.Id, // PhoneTypeId = Guid.Parse(Config.MobilePhoneType), // CreatedDate = DateTime.Now // }); //} //if (userModel.WorkPhoneNumber != null) //{ // context.ClientPhoneAssociatives.Add(new ClientPhoneAssociative() // { // Id = model.Id, // ClientPhoneId = wPhone.Id, // PhoneTypeId = Guid.Parse(Config.WorkPhoneType), // CreatedDate = DateTime.Now // }); //} //if (userModel.HomePhoneNumber != null) //{ // context.ClientPhoneAssociatives.Add(new ClientPhoneAssociative() // { // Id = model.Id, // ClientPhoneId = hPhone.Id, // PhoneTypeId = Guid.Parse(Config.HomePhoneType), // CreatedDate = DateTime.Now // }); //} //await context.SaveChangesAsync(); await SendConfirmationEmail(user.Id, EmailMessage.NewAccountEmailConfirmation); } } return result; } catch (Exception ex) { //if error on creating address and phone need to remove login UserManager.Delete(user); ErroLogging.LogError(ex); throw ex; } }
public async Task<UpdatedDemographicModel> DemographicUserGetAsync(String AspUserId) { try { ApplicationUser aspUser = await FindAspUserByUserId(AspUserId); UpdatedDemographicModel user = new UpdatedDemographicModel(); Client client = new Client(); using (WW_DevEntities context = new WW_DevEntities()) { client = context.Clients.Where(q => q.AspUserId == AspUserId).FirstOrDefault(); if (client != null) { // TODO: // implement dob user.FirstName = client.FirstName; user.MiddleName = client.MiddleName; user.LastName = client.LastName; user.Suffix = client.Suffix; //user.SSN = client.SSN; //user.DateOfBirth = client.DateOfBirth.Value.ToShortDateString() ?? client.DateOfBirth.Value.ToShortDateString(); user.Email = aspUser.Email; } } return user; } catch (Exception ex) { ErroLogging.LogError(ex); throw ex; } }