public IHttpActionResult PostContactToUser(int userId, Contact contact) { if (!ModelState.IsValid) { return BadRequest(ModelState); } //TODO - make check on userId in ContactRepo _userContactRepo.Post(userId, contact); return Ok(contact); }
public Contact UpdateContact(int userId, int contactId, Contact contactUpdated) { var contact = GetContactById(userId, contactId); if (contact == null) { return null; } contact.FirstName = contactUpdated.FirstName; contact.LastName = contactUpdated.LastName; contact.Address = contactUpdated.Address; contact.City = contactUpdated.City; contact.Zip = contactUpdated.Zip; contact.Email = contactUpdated.Email; _ctx.SaveChanges(); return contact; }
public IHttpActionResult PutContactToUser(int userId, int contactId, Contact contact) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (contactId != contact.Id) { return BadRequest(); } //TODO - Develop validation approach contact = _userContactRepo.UpdateContact(userId, contactId, contact); if (contact == null) { return NotFound(); } return Ok(contact); }
public void Post(int userId, Contact contact) { contact.userId = userId; _ctx.Contacts.Add(contact); _ctx.SaveChanges(); }