public static void Registration(UserModel NewUser) { UsersEntityModel newUser = NewUser; newUser.Password = Verification(newUser.Password); if (DbContext.db.Users.Where(us => us.Login == newUser.Login).Count() == 0) { DbContext.db.Users.Add(newUser); DbContext.db.SaveChanges(); } else { throw new Exception("Данный логин уже используется, введите другой логин и продолжите регистрацию..."); } }
public async Task <IdentityResult> CreateUserAsync(RegisterViewModel request) { var newUser = new UsersEntityModel { UserName = request.Email, FirstName = request.FirstName, SecondName = request.SecondName, Patronymic = request.Patronymic, Email = request.Email, PhoneNumber = request.PhoneNumber }; var result = await _userManager.CreateAsync(newUser, request.Password); if (result.Succeeded) { return(await _userManager.AddToRoleAsync(newUser, request.RoleName)); } else { return(null); } }