public IActionResult Register() { SetBreadcrums(""); UserProfileRegisterVM model = new UserProfileRegisterVM(); return(View(model)); }
public async Task <IActionResult> Register(UserProfileRegisterVM model) { SetBreadcrums(""); ValidateRegister(model); if (!ModelState.IsValid) { return(View(model)); } if (!commonService.Users_CheckUserByEmail(model.Id, model.Email)) { SetErrorMessage("Вече съществува потребител с този мейл"); return(View(model)); } model.CourtId = userContext.CourtId; var user = new ApplicationUser { UserName = model.Email, Email = model.Email, LawUnitId = model.LawUnitId, CourtId = userContext.CourtId, WorkNotificationToMail = model.WorkNotificationToMail, IsActive = true }; IdentityResult res = null; if (AccountConstants.PasswordLoginEnabled) { res = await userManager.CreateAsync(user, model.Password); } else { res = await userManager.CreateAsync(user); } if (res.Succeeded) { commonService.Users_GenerateEissId(user.Id); this.SaveLogOperation(true, user.Id); SetSuccessMessage(MessageConstant.Values.SaveOK); return(RedirectToAction(nameof(Index))); } else { SetErrorMessage(MessageConstant.Values.SaveFailed); return(View(model)); } }
void ValidateRegister(UserProfileRegisterVM model) { if (AccountConstants.PasswordLoginEnabled) { if (string.IsNullOrEmpty(model.Password)) { ModelState.AddModelError(nameof(UserProfileRegisterVM.Password), "Въведете 'Парола'."); } if (model.Password != model.Password2) { ModelState.AddModelError(nameof(UserProfileRegisterVM.Password), "Двете копия на паролата не съвпадат."); } } if (model.LawUnitId <= 0) { ModelState.AddModelError(nameof(UserProfileRegisterVM.LawUnitId), "Изберете 'Служител.'"); } string userVal = commonService.Users_ValidateEmailLawUnit(null, model.LawUnitId); if (!string.IsNullOrEmpty(userVal)) { ModelState.AddModelError(nameof(UserProfileRegisterVM.LawUnitId), userVal); } }