public HttpResponseMessage Put([FromBody] Models.shop updatedShop) { try { using (var db = new SONRCoffee.Data.SONRCoffeeDbContext()) { var originalShop = db.shops.Find(updatedShop.ShopId); if (originalShop != null) { db.Entry(originalShop).CurrentValues.SetValues(updatedShop); db.SaveChanges(); } else { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "shop id not recognized")); } } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex)); } return(Request.CreateResponse(HttpStatusCode.OK, JObject.FromObject(updatedShop))); }
public HttpResponseMessage Post([FromBody] Models.shop newShop) { try { newShop.ShopId = 0; using (var db = new SONRCoffee.Data.SONRCoffeeDbContext()) { db.shops.Add(newShop); db.SaveChanges(); } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex)); } return(Request.CreateResponse(HttpStatusCode.OK, JObject.FromObject(newShop))); }