public async Task <IActionResult> OnPostAsync() { if (!string.IsNullOrEmpty(Password)) { if (Password != PasswordCheck) { ModelState.AddModelError("Password", "Passwords does not match"); } if (Password.Length < 6) { ModelState.AddModelError("Password", "Password needs to be at least 5 chars."); } } else { if (Id == 0) { ModelState.AddModelError("Password", "You need to set a password"); } } if (!IsValidEmail(Email)) { ModelState.AddModelError("Email", "Not a valid e-mail address."); } if (!ModelState.IsValid) { return(Page()); } UserDto userDto = null; if (Id > 0) { userDto = await _apiManager.GetUserById(Id); } else { userDto = new UserDto(); } userDto.UserName = UserName; userDto.Email = Email; if (!string.IsNullOrEmpty(Password)) { userDto.Password = Password; } if (_sessionManager.IsAdministrator) { userDto.IsAdministrator = IsAdministrator; } if (userDto.Id == 0) { var result = await _apiManager.CreateUser(userDto); return(new RedirectToPageResult("/UserInfo", new { result.Id })); } await _apiManager.UpdateUser(userDto); return(new RedirectToPageResult("/UserInfo", new { userDto.Id })); }