예제 #1
0
        public IHttpActionResult PostSaleOrder(SaleOrder saleOrder)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }
            if(saleOrder.CustomerID==Guid.Empty)
            {
                return BadRequest();
            }
            SaleOrder newSaleOrder = SaleOrder.Create(saleOrder.CustomerID);
            db.SaleOrders.Add(newSaleOrder);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (SaleOrderExists(saleOrder.ID))
                {
                    return Conflict();
                }
                else
                {
                    throw;
                }
            }

            return CreatedAtRoute("DefaultApi", new { id = saleOrder.ID }, saleOrder);
        }
예제 #2
0
 public static SaleOrder Create(Guid customerID,SaleOrder parentSaleOrder = null)
 {
     SaleOrder saleOrder = new SaleOrder();
     saleOrder.CustomerID = customerID;
     saleOrder.Items = new HashSet<SaleOrderItem>();
     saleOrder.OrderTime = DateTime.Now;
     saleOrder.ParentSaleOrder = parentSaleOrder;
     return saleOrder;
 }
예제 #3
0
        public static SaleOrder Create(Guid customerID, SaleOrder parentSaleOrder = null)
        {
            SaleOrder saleOrder = new SaleOrder();

            saleOrder.CustomerID      = customerID;
            saleOrder.Items           = new HashSet <SaleOrderItem>();
            saleOrder.OrderTime       = DateTime.Now;
            saleOrder.ParentSaleOrder = parentSaleOrder;
            return(saleOrder);
        }
예제 #4
0
        public SaleOrder UpdateSaleOrder(SaleOrder saleOrder)
        {
            if (saleOrder.ID==Guid.Empty)
            {
                saleOrder.OrderTime = DateTime.Now;
                db.SaleOrders.Add(saleOrder);
            }
            else
            {
                var existingSaleOrder = db.SaleOrders.Find(saleOrder.ID);

            }
            return saleOrder;
        }
예제 #5
0
        public IHttpActionResult PutSaleOrder(Guid id, SaleOrder saleOrder)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != saleOrder.ID)
            {
                return BadRequest();
            }

            db.Entry(saleOrder).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!SaleOrderExists(id))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return StatusCode(HttpStatusCode.NoContent);
        }
예제 #6
0
 public void UpdateBy(SaleOrder saleOrder)
 {
     this.CustomerID = saleOrder.CustomerID;
     this.DeliveryAddress = saleOrder.DeliveryAddress;
     this.UpdateItems(saleOrder.Items);
 }