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> 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 void Detach(T entity) { if (entity != null) { _context.Entry(entity).State = EntityState.Detached; } }
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 <ActionResult> Edit([Bind(Include = "Id,name,Phone,Email,DateOfBirth")] Contact contact) { if (ModelState.IsValid) { db.Entry(contact).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(contact)); }
public bool UpdateContact(Person person) { if (person == null) { return(false); } _context.Entry(person).State = EntityState.Modified; _context.SaveChanges(); return(true); }
public IActionResult Put(string id, Users user) { if (id != user.Id) { return(BadRequest("Id's do not match!")); } _context.Entry(user).State = EntityState.Modified; try { _context.SaveChanges(); } catch (Exception e) { return(BadRequest(e.Message)); } return(Ok()); }
public void Update(Contact contact) { _ctx.Entry(contact).State = EntityState.Modified; _ctx.SaveChanges(); }