public IHttpActionResult createcustomer(customerdto customerdto) { if (!ModelState.IsValid) { return(BadRequest()); } var customer = Mapper.Map <customerdto, customer>(customerdto); db.customers.Add(customer); db.SaveChanges(); customerdto.id = customer.id; return(Created(new Uri(Request.RequestUri + "/" + customer.id), customerdto)); }
public void updatecustomer(int id, customerdto customerdto) { if (!ModelState.IsValid) { throw new HttpResponseException(HttpStatusCode.BadRequest); } var customerindb = db.customers.SingleOrDefault(m => m.id == id); if (customerindb == null) { throw new HttpResponseException(HttpStatusCode.NotFound); } Mapper.Map <customerdto, customer>(customerdto, customerindb); db.SaveChanges(); }