public async Task <IActionResult> Register([FromServices] AppDbContextFactory factory, RegisterModel model) { if (!ModelState.IsValid) { return(PartialView("RegisterFormContent", model)); } using (var context = factory.CreateContext()) { var phoneExists = model.CheckPhone(context); if (phoneExists) { ModelState.AddModelError("form", _localizer["AuthController_UserWithPhoneExists"]); } var emailExists = model.CheckEmail(context); if (emailExists) { ModelState.AddModelError("form", _localizer["AuthController_UserWithEmailExists"]); } if (!ModelState.IsValid) { return(PartialView("RegisterFormContent", model)); } var entity = new UserEntity(); entity.Name = model.Name; entity.Email = model.Email; entity.Phone = model.Phone; entity.PasswordHash = model.Password.ComputeHashMD5(); context.Users.Add(entity); await context.SaveChangesAsync(); } ViewBag.RedirectUrl = Url.Action("Login", "Auth"); return(PartialView("RegisterFormContent")); }