public async Task <IActionResult> PutContact([FromRoute] int id, [FromBody] Contact contact) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != contact.Id) { return(BadRequest()); } _context.Entry(contact).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ContactExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutMyContacts(string id, Contacts contact) { if (id != contact.ContactId) { return(BadRequest()); } _context.Entry(contact).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MyContactsExists(id)) { return(NotFound()); } else { throw; } } return(Ok()); }
public async Task <IActionResult> PutContact([FromRoute] int id, [FromBody] Contact contact) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != contact.Id || _userManager.GetUserId(User) != contact.UserId) { return(BadRequest()); } _context.Entry(contact).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ContactExists(id)) { return(NotFound()); } throw; } return(new StatusCodeResult(StatusCodes.Status204NoContent)); }
public async Task <IActionResult> Post(Contact contact) { try { if (_db.Contacts.FirstOrDefault() != null) { var cont = await _db.Contacts.FirstOrDefaultAsync(p => p.Key == contact.Key); if (cont != null) { return(BadRequest()); } } await _db.Contacts.AddAsync(contact); await _db.SaveChangesAsync(); return(Ok()); } catch { throw; } }
public async Task <IActionResult> Create([Bind("Id,FirstName,Lastname")] Contact contact) { if (ModelState.IsValid) { _context.Add(contact); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(contact)); }
public async Task <IActionResult> Create([Bind("Id,Name,Address,City,State,PostalCode,Phone,Email")] Contact contact) { if (ModelState.IsValid) { _context.Add(contact); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(contact)); }
public async Task <IActionResult> Create(Contact contact) { if (ModelState.IsValid) { _dbContext.Contacts.Add(contact); await _dbContext.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(contact)); }
public async Task <ActionResult> Create([Bind(Include = "Id,name,Phone,Email,DateOfBirth")] Contact contact) { if (ModelState.IsValid) { db.Contacts.Add(contact); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(contact)); }
public async Task <IActionResult> Create(Contact contact) { if (ModelState.IsValid) { contact.UserId = _userManager.GetUserId(User); _context.Contacts.Add(contact); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(contact)); }
public async Task <IActionResult> Create(Contact contact) { _context.Add(contact); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } _context.Attach(Contact).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ContactExists(Contact.Id)) { return(NotFound()); } else { throw; } } return(RedirectToPage("./Index")); }
public async Task <Contact> Create(Contact contact) { var created = await _context.Contact.AddAsync(contact); await _context.SaveChangesAsync(); return(created.Entity); }
public async Task Save(ContactNumber contactNumber = null) { if (contactNumber != null) { _context.ContactNumbers.Add(contactNumber); } await _context.SaveChangesAsync(); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } _context.Contacts.Add(Contact); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } Contact = await _context.Contacts.FindAsync(id); if (Contact != null) { _context.Contacts.Remove(Contact); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
public async Task Save(Contact contact = null) { if (contact != null) { _context.Contacts.Add(contact); } try { await _context.SaveChangesAsync(); } catch (Exception e) { Console.WriteLine(e); throw; } }
public async Task Add(Contact item) { await _context.Contacts.AddAsync(item); await _context.SaveChangesAsync(); }
public async Task Insert(T entity) { _context.Set <T>().Add(entity); await _context.SaveChangesAsync(); }