Exemple #1
0
        public int UpdateLineItem(int lineId, OrderLineItemDO lineItem)
        {
            var item = db.OrderLineItems.FirstOrDefault(l => l.LineId == lineId);

            item.Product = lineItem.Product;
            // Get the difference in quantity of the item already present and new item
            int difference = lineItem.Quantity - item.Quantity;
            // Check if we have enough products
            int reduceResult = UpdateProductQuantity(difference, lineItem.Product.ProductId);

            if (reduceResult < 0)
            {
                return(reduceResult);
            }
            item.Quantity = lineItem.Quantity;
            item.Total    = lineItem.Total;
            db.OrderLineItems.Update(item);
            // Update Product Quantity
            var updatedOrder = db.Orders.FirstOrDefault(o => o.OrderId == item.OrderId);

            updatedOrder.Total = GetLineItemsForOrder(item.OrderId).Sum(l => l.Total);
            // Ensure that the same product orders are aggregated
            UpdateOrder(updatedOrder);
            db.SaveChanges();
            return(item.OrderId);
        }
 public int UpdateLineItem(OrderLineItemDO lineItem)
 {
     db.Update(lineItem);
     db.SaveChanges();
     return(lineItem.OrderId);
 }