예제 #1
0
 // 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));
     }
 }
예제 #2
0
 // 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));
     }
 }
예제 #3
0
 // 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));
     }
 }
예제 #4
0
 // 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));
     }
 }
예제 #5
0
 // 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));
     }
 }
예제 #6
0
 // 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));
     }
 }