public IHttpActionResult PutClient(int id, ClientViewModel clientViewModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != clientViewModel.ClientId) { return(BadRequest()); } Client client = ViewModelMapper.ToModelClients(clientViewModel); db.Entry(client).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!ClientExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult PostClient(ClientViewModel clientViewModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } Client client = ViewModelMapper.ToModelClients(clientViewModel); db.Clients.Add(client); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = client.ClientId }, ViewModelMapper.ToViewModelClients(client))); }