public async Task <Contact> AddContact(Contact contact) { contact.Id = 0; _context.Contacts.Add(contact); await _context.SaveChangesAsync(); return(contact); }
// To protect from overposting attacks, enable the specific properties you want to bind to, for // more details, see https://aka.ms/RazorPagesCRUD. public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } _context.Attach(ContactModel).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ContactModelExists(ContactModel.Id)) { return(NotFound()); } else { throw; } } return(RedirectToPage("./Index")); }
// To protect from overposting attacks, enable the specific properties you want to bind to, for // more details, see https://aka.ms/RazorPagesCRUD. public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } _context.ContactModel.Add(ContactModel); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } ContactModel = await _context.ContactModel.FindAsync(id); if (ContactModel != null) { _context.ContactModel.Remove(ContactModel); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }