Exemplo n.º 1
0
        // PUT api/Order/5
        public HttpResponseMessage PutOrder(int id, Order order)
        {
            if (!ModelState.IsValid)
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }

            if (id != order.OrderId)
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest);
            }

            db.Orders.Attach(order);
            db.ObjectStateManager.ChangeObjectState(order, EntityState.Modified);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException ex)
            {
                return Request.CreateErrorResponse(HttpStatusCode.NotFound, ex);
            }

            return Request.CreateResponse(HttpStatusCode.OK);
        }
Exemplo n.º 2
0
        // POST api/Order
        public HttpResponseMessage PostOrder(Order order)
        {
            if (ModelState.IsValid)
            {
                db.Orders.AddObject(order);
                db.SaveChanges();

                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, order);
                response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = order.OrderId }));
                return response;
            }
            else
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }
        }
 /// <summary>
 /// Create a new Order object.
 /// </summary>
 /// <param name="orderId">Initial value of the OrderId property.</param>
 /// <param name="productId">Initial value of the ProductId property.</param>
 /// <param name="quantity">Initial value of the Quantity property.</param>
 /// <param name="unitPrice">Initial value of the UnitPrice property.</param>
 /// <param name="totalPrice">Initial value of the TotalPrice property.</param>
 public static Order CreateOrder(global::System.Int32 orderId, global::System.Int32 productId, global::System.Int32 quantity, global::System.Int32 unitPrice, global::System.Int32 totalPrice)
 {
     Order order = new Order();
     order.OrderId = orderId;
     order.ProductId = productId;
     order.Quantity = quantity;
     order.UnitPrice = unitPrice;
     order.TotalPrice = totalPrice;
     return order;
 }
 /// <summary>
 /// Deprecated Method for adding a new object to the Orders EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToOrders(Order order)
 {
     base.AddObject("Orders", order);
 }