Exemplo n.º 1
0
        public OrderAndProducts GetOrderAndProducts(int?id)
        {
            var resultOrder = GetAll().Where(o => o.ID == id)
                              .Select(o => new
            {
                Order    = o,
                Customer = o.Customer,
                Products = o.ProductOrders.Select(po => new { po.Product, po.Quantity })
            })
                              .ToList()
                              .Select(r => new OrderAndProducts()
            {
                Order = new OrderWithTotalPrice()
                {
                    Order      = r.Order,
                    Customer   = r.Customer,
                    TotalPrice = r.Products.Sum(p => p.Product.Price * p.Quantity)
                },
                Products = r.Products.Select(pwq => new ProductWithQuantity()
                {
                    Product    = pwq.Product,
                    Quantity   = pwq.Quantity,
                    TotalPrice = pwq.Product.Price * pwq.Quantity
                })
                           .ToList()
            })
                              .FirstOrDefault();

            if (resultOrder == null)
            {
                resultOrder = new OrderAndProducts();
            }
            return(resultOrder);
        }
 public OrdersSearchOrderVM()
 {
     OrderAndProducts = new OrderAndProducts();
 }