private Domain.ApplicationUser ClientVMToApplicationUser(ClientParticipantCreateEditViewModel vm) { if (string.IsNullOrWhiteSpace(vm.ID)) { return(new Domain.ApplicationUser { AddedWhen = DateTime.UtcNow, Active = vm.Login.Active, Forename = vm.Login.Forename, Surname = vm.Login.Surname, UserName = vm.Name, Email = vm.Login.Email }); } else { var existingUser = participantsProcessor.GetClientById(vm.ID).ApplicationUser; existingUser.Active = vm.Login.Active; existingUser.Forename = vm.Login.Forename; existingUser.Surname = vm.Login.Surname; existingUser.UserName = vm.Name; existingUser.Email = vm.Login.Email; return(existingUser); } }
public ActionResult EditClient(string id) { if (string.IsNullOrWhiteSpace(id)) { return(new HttpNotFoundResult()); } var client = participantsProcessor.GetClientById(id); if (client == null) { return(new HttpNotFoundResult()); } var vm = new ClientParticipantCreateEditViewModel { Login = ClientToLoginVM(client) }; PopulateClientRoles(); return(PartialView("_CreateEditClient", vm)); }
public async Task <ActionResult> EditClient(ClientParticipantCreateEditViewModel vm) { var success = ModelState.IsValid; var message = string.Empty; try { if (success) { (success, message) = await participantsProcessor.UpdateClient(ClientVMToApplicationUser(vm)); } else { message = string.Join("<br/>", GetModelStateErrorMessages()); } } catch (Exception e) { success = false; message = $"Error updating client user: {e.Message}"; } return(Json(new { success, message })); }