public async Task <IActionResult> ViewBill(int tableNumber)
        {
            if (await _table.IsValidTableNumber(tableNumber) == false)
            {
                return(RedirectToAction("TableNotExistError", "Home"));
            }
            var table = await _table.GetTableByTableNumber(tableNumber);

            var order = await _order.GetOrderByTable(table.Id);

            if (order == null)
            {
                return(RedirectToAction("NoOrderError", "Home"));
            }

            var server = await _people.GetPersonById(order.ServerId);

            var orderDetails = await _order.GetOrderDetailByDiningTable(table.Id);

            BillDisplayModel bill = new BillDisplayModel
            {
                OrderId     = order.Id,
                TableNumber = tableNumber,
                Server      = server.FullName,
                SubTotal    = order.SubTotal,
                Tax         = order.Tax,
                Total       = order.Total,
                BillPaid    = order.BillPaid
            };

            if (orderDetails == null)
            {
                return(RedirectToAction("NoOrderError", "Home"));
            }
            else
            {
                foreach (var detail in orderDetails)
                {
                    var food = await _food.GetFoodById(detail.FoodId);

                    bill.OrderDetails.Add(new OrderDetailDisplayModel
                    {
                        Id          = detail.Id,
                        TableNumber = table.TableNumber,
                        Server      = server.FullName,
                        FoodName    = food.FoodName,
                        Price       = food.Price,
                        Quantity    = detail.Quantity,
                        OrderDate   = detail.OrderDate
                    });
                }
            }

            return(View(bill));
        }
Пример #2
0
        public async Task <IActionResult> ViewOrderByTable(int tableNumber)
        {
            if (await _table.IsValidTableNumber(tableNumber) == false)
            {
                return(RedirectToAction("TableNotExistError", "Home"));
            }

            var table = await _table.GetTableByTableNumber(tableNumber);

            var displayDetails = new List <OrderDetailDisplayModel>();
            var orderDetails   = await _order.GetOrderDetailByDiningTable(table.Id);

            if (orderDetails.Count == 0)
            {
                return(RedirectToAction("NoOrderError", "Home"));
            }
            else
            {
                var server = await _people.GetPersonById(orderDetails[0].ServerId);

                foreach (var detail in orderDetails)
                {
                    var food = await _food.GetFoodById(detail.FoodId);

                    displayDetails.Add(new OrderDetailDisplayModel
                    {
                        Id          = detail.Id,
                        TableNumber = tableNumber,
                        Server      = server.FullName,
                        FoodName    = food.FoodName,
                        Price       = food.Price,
                        Quantity    = detail.Quantity,
                        OrderDate   = detail.OrderDate
                    });
                }
                return(View(displayDetails));
            }
        }