public HttpResponseMessage Post([FromBody] InsertOutlets addoutlet) { try { using (SalesForceEntities entities = new SalesForceEntities()) { entities.CreateOutlet(addoutlet.Name, addoutlet.ContactNo, addoutlet.Barcode, addoutlet.Longitude, addoutlet.Latitude, addoutlet.OwnerName, addoutlet.Email, addoutlet.Status, addoutlet.RouteId); entities.SaveChanges(); var message = Request.CreateResponse(HttpStatusCode.Created, addoutlet); // message.Headers.Location = new Uri(Request.RequestUri + Outlet.Id.ToString()); return(message); } } catch (Exception ex) { return(Request.CreateResponse(HttpStatusCode.BadRequest, ex)); } }
public HttpResponseMessage Put([FromBody] InsertOutlets addoutlet) { try { using (SalesForceEntities entities = new SalesForceEntities()) { var entity = entities.Outlets.FirstOrDefault(d => d.Id == addoutlet.Id); if (entity == null) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Outlet with " + addoutlet.Id.ToString() + " not found")); } else { entities.UpdateOutlets(addoutlet.Id, addoutlet.Name, addoutlet.ContactNo, addoutlet.Longitude, addoutlet.Latitude, addoutlet.OwnerName, addoutlet.Email, addoutlet.Status, addoutlet.RouteId); entities.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK, entity)); } } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }