public async Task <IActionResult> Edit(ContactsEditViewModel model) { if (ModelState.IsValid) { Contact contact = new Contact { Id = model.Id, Email = model.Email, Name = model.Name, PhoneNumber = model.PhoneNumber, Note = model.Note }; try { _context.Add(contact); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ContactExists(contact.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(model)); }
// GET: Contacts/Edit/5 public async Task <IActionResult> Edit(int?id) { if (id == null) { return(NotFound()); } Contact contact = await _context.Contacts.FindAsync(id); if (contact == null) { return(NotFound()); } ContactsEditViewModel model = new ContactsEditViewModel { Email = contact.Email, Name = contact.Name, PhoneNumber = contact.PhoneNumber, Note = contact.Note }; return(View(model)); }