public bool SaveProfile(BoxUserProfile profile) { var data = _context.BoxUserProfiles.FirstOrDefault(_profile => _profile.ProfileId == profile.ProfileId); if (data != null) { data.FirstName = profile.FirstName; data.LastName = profile.LastName; data.Contact = profile.Contact; data.Active = true; data.ModifiedDate = DateTime.UtcNow; _context.Update(data); } _context.SaveChanges(); return(true); }
public async Task <IActionResult> Register(LoginModel model) { var userAlreadyExist = await ResolveNewUserEmail(model.Username); if (userAlreadyExist) { ModelState.AddModelError("", "User already exist with this email."); return(View()); } var id = Guid.NewGuid(); BoxUserProfile profile = new BoxUserProfile() { ProfileId = id, IdentitytId = id, Active = false }; await _userRepository.AddNewUser(profile, model.Username, model.Password); return(RedirectToAction("index", "home")); }
public async Task <bool> AddNewUser(BoxUserProfile user, string username, string password) { var boxUser = new BoxIdentityUser() { Email = username, UserName = username, IdentitytId = user.IdentitytId }; var identity = await _userManager.CreateAsync(boxUser, password); if (identity.Succeeded) { user.CreationDate = DateTime.UtcNow; user.Organization = new Organization { Active = false, OrganizationId = Guid.NewGuid() }; await _context.Organizations.AddAsync(user.Organization); await _context.BoxUserProfiles.AddAsync(user); try { await _context.SaveChangesAsync(); return(identity.Succeeded); } catch { var deleteUser = await _userManager.FindByEmailAsync(boxUser.Email); await _userManager.DeleteAsync(deleteUser); } } throw new Exception($"{nameof(AddNewUser)}:" + $" User identity not created"); }