public IdentityUser CreateIdentityUser(IdentityUser identityUser) { Contract.NotNull <ArgumentNullException>(identityUser); var user = mapper.Map <User>(identityUser); var updatedUser = unitOfWork.InsertOrUpdate(user); unitOfWork.Commit(); return(mapper.Map <IdentityUser>(updatedUser)); }
public AchievementType?ChallengePosted(Guid userId) { var user = identityUnitOfWork.Get <User>(userId); user.PostedTasksQuantity++; var result = GetAddedBadge(user, $"Posted{user.PostedTasksQuantity}"); identityUnitOfWork.InsertOrUpdate(user); identityUnitOfWork.Commit(); return(result); }
/// <summary>Registers the first user admin without confirmation.</summary> /// <param name="uow"> The uow. </param> /// <param name="model"> The model. </param> /// <param name="returnUrl"> URL of the return. </param> /// <returns>The asynchronous result that yields an IdentityUserEntity.</returns> private async Task <IdentityUserEntity> RegisterFirstUserAdminWithoutConfirmation(IIdentityUnitOfWork uow, RegisterViewModel model, string returnUrl) { var admin = uow.RoleRepository.FindByLoweredName("ADMINISTRATOR") ?? uow.RoleRepository.Add( new IdentityRoleEntity { ApplicationId = 0, Description = "Administrator-Role", Identifier = Guid.NewGuid(), NormalizedName = "ADMINISTRATOR", Name = "Administrator" }); uow.Commit(); var user = new IdentityUserEntity { Name = model.Name, Email = model.Email, Phone = model.Phone }; var result = await _userManager.CreateAsync(user, model.Password); if (result.Succeeded) { await _userManager.AddToRoleAsync(user, admin.Name); var code = await _userManager.GenerateEmailConfirmationTokenAsync(user); await _userManager.ConfirmEmailAsync(user, code); } return(user); }