// GET: Contacts/Edit/5 public async Task <IActionResult> Edit(int?id) { if (id == null) { return(NotFound()); } Account account = await context.Accounts.FindAsync(id); if (account == null) { return(NotFound()); } AccountsEditViewModel model = new AccountsEditViewModel { Id = account.Id, Username = account.Username, Password = account.Password, FirstName = account.FirstName, LastName = account.LastName, PersonalId = account.PersonalId, PhoneNumber = account.PhoneNumber, Email = account.Email, Start = account.Start, Active = account.Active, Released = account.Released }; return(View(model)); }
public async Task <IActionResult> Edit(AccountsEditViewModel model) { if (ModelState.IsValid) { Account account = new Account { Id = model.Id, FirstName = model.FirstName, LastName = model.LastName, PhoneNumber = model.PhoneNumber, Email = model.Email, Username = model.Username, Password = model.Password, Active = model.Active, Role = model.Role, Released = model.Released, PersonalId = model.PersonalId, Start = model.Start }; try { context.Update(account); await context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!context.Accounts.Any(e => e.Id == model.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(model)); }