Example #1
0
        public CustomerOrdersVM GetCustomerOrdersVM(int?CustomerID, int?SortBy)
        {
            var customerOrdersVM = new CustomerOrdersVM();

            if (CustomerID != null)
            {
                customerOrdersVM.CustomerID = CustomerID.Value;
                var orders = GetCustomerOrders(customerOrdersVM.CustomerID);
                foreach (var order in orders)
                {
                    var orderVM = new OrderVM()
                    {
                        CustomerID    = customerOrdersVM.CustomerID,
                        LocationID    = order.LocationID,
                        LocationName  = order.Location.LocationName,
                        State         = order.Location.State,
                        OrderDateTime = order.OrderDateTime,
                        Total         = order.Total
                    };
                    if (order.DrinkOrders != null)
                    {
                        foreach (var drinkOrder in order.DrinkOrders)
                        {
                            var drinkOrderVM = new DrinkOrderVM
                            {
                                DrinkId   = drinkOrder.DrinkId,
                                DrinkName = drinkOrder.Drink.DrinkName,
                                ABV       = drinkOrder.Drink.ABV,
                                Quantity  = drinkOrder.Quantity,
                                Price     = drinkOrder.Drink.Price
                            };
                            orderVM.DrinkOrders.Add(drinkOrderVM);
                        }
                    }


                    customerOrdersVM.Orders.Add(orderVM);
                }
                if (SortBy != null)
                {
                    customerOrdersVM.SortBy = SortBy.Value;
                }
                customerOrdersVM.Orders = SortOrders(customerOrdersVM.SortBy, customerOrdersVM.Orders);
            }


            return(customerOrdersVM);
        }
Example #2
0
        public LocationOrdersVM GetLocationOrdersVM(int?LocationID, int?SortBy)
        {
            var locationOrdersVM = new LocationOrdersVM();

            if (LocationID != null)
            {
                locationOrdersVM.LocationID = LocationID.Value;
                var orders = GetLocationOrders(locationOrdersVM.LocationID);
                foreach (var order in orders)
                {
                    var orderVM = new OrderVM()
                    {
                        CustomerID    = order.CustomerID,
                        CustomerName  = order.Customer.Name,
                        LocationID    = order.LocationID,
                        LocationName  = order.Location.LocationName,
                        State         = order.Location.State,
                        OrderDateTime = order.OrderDateTime,
                        Total         = order.Total
                    };
                    if (order.DrinkOrders != null)
                    {
                        foreach (var drinkOrder in order.DrinkOrders)
                        {
                            var drinkOrderVM = new DrinkOrderVM
                            {
                                DrinkId   = drinkOrder.DrinkId,
                                DrinkName = drinkOrder.Drink.DrinkName,
                                ABV       = drinkOrder.Drink.ABV,
                                Quantity  = drinkOrder.Quantity,
                                Price     = drinkOrder.Drink.Price
                            };
                            orderVM.DrinkOrders.Add(drinkOrderVM);
                        }
                    }


                    locationOrdersVM.Orders.Add(orderVM);
                }
            }
            if (SortBy != null)
            {
                locationOrdersVM.SortBy = SortBy.Value;
            }
            locationOrdersVM.Orders = SortOrders(locationOrdersVM.SortBy, locationOrdersVM.Orders);
            return(locationOrdersVM);
        }