コード例 #1
0
        public void AcceptOrder(int orderId)
        {
            var order      = OrderRep.Get(orderId);
            var prodAccept = order.Products;
            var warehouse  = LocationRep.Get(order.LocationId);

            foreach (var item in prodAccept)
            {
                var prod = warehouse.Products.Where(p => p.Product.ProductId == item.Product.ProductId).FirstOrDefault();
                if (prod != null)
                {
                    prod.Value         += item.Value;
                    prod.TotalQuantity += (decimal)item.Value;
                    prod.TotalPrice    += item.Price * (decimal)item.Value;
                    prod.Price          = prod.TotalPrice / prod.TotalQuantity;
                }
                else
                {
                    warehouse.Products.Add
                    (
                        new ProductStorage
                    {
                        Product = ProductRep.Get(item.Product.ProductId),
                        Value   = item.Value,
                        Price   = item.Price
                    });
                }
            }
            order.Accept     = true;
            order.AcceptDate = DateTime.Today;
        }