// PUT: api/EditOrder/5 public HttpResponseMessage EditOrder(int id, [FromBody] Order order) { try { using (EshopEntities db = new EshopEntities()) { Order s = db.Orders.SingleOrDefault(b => b.OrderID == id); if (s != null) { s.OrderID = id; s.CustomerID = order.CustomerID; s.OrderDate = order.OrderDate; s.ShipAddress = order.ShipAddress; db.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK, s)); } else { return(null); } } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex.Message)); } }
// PUT: api/Product/5 public HttpResponseMessage Put(int id, [FromBody] Product value) { try { using (EshopEntities db = new EshopEntities()) { Product s = db.Products.SingleOrDefault(b => b.ProductID == id); if (s != null) { s.ProductID = id; s.CategoryID = value.CategoryID; s.UnitPrice = value.UnitPrice; s.ProductName = value.ProductName; s.Quantity = value.Quantity; db.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK, s)); } else { return(null); } } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex.Message)); } }
// PUT: api/Category/5 public HttpResponseMessage Put(int id, [FromBody] Category value) { try { using (EshopEntities db = new EshopEntities()) { Category s = db.Categories.SingleOrDefault(b => b.CategoryID == id); if (s != null) { s.CategoryID = id; s.CategoryName = value.CategoryName; s.Description = value.Description; db.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK, s)); } else { return(null); } } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex.Message)); } }
// POST: api/AddOrder public HttpResponseMessage AddOrder([FromBody] Order order) { try { using (EshopEntities db = new EshopEntities()) { db.Orders.Add(order); db.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.Created)); } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex.Message)); } }
// POST: api/Product public HttpResponseMessage Post([FromBody] Product value) { try { using (EshopEntities db = new EshopEntities()) { db.Products.Add(value); db.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.Created)); } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex.Message)); } }
// DELETE: api/DeleteOrder/5 public HttpResponseMessage DeleteOrder(int id) { try { using (EshopEntities db = new EshopEntities()) { Order o = db.Orders.SingleOrDefault(x => x.OrderID == id); db.Orders.Remove(o); db.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK)); } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex.Message)); } }