Exemple #1
0
        public IActionResult Index(string id)
        {
            var orders              = orderRepository.Gets().ToList();
            var orderDetails        = orderDetailRepository.Gets().ToList();
            var productOrderDetails = productOrderDetailRepository.Gets().ToList();
            var products            = productRepository.Gets().ToList();
            var productTypes        = productTypeRepository.Gets().ToList();

            if (id != null)
            {
                var dashboardView = (from o in orders
                                     join od in orderDetails on o.OrderId equals od.OrderId
                                     join pod in productOrderDetails on od.OrderDetailId equals pod.OrderDetailId
                                     join p in products on pod.ProductId equals p.ProductId
                                     join pt in productTypes on p.ProductTypeId equals pt.ProductTypeId
                                     where od.Paid == true &&
                                     (!string.IsNullOrEmpty(od.UserId) && string.Compare(od.UserId.Trim(), id) == 0)
                                     select new DashboardViewModel()
                {
                    OrderID = o.OrderId,
                    StartTime = o.StarTime.ToString(),
                    EndTime = o.EndTime.ToString(),
                    ProductName = p.Name,
                    Count = pod.Count,
                    Price = p.Price,
                    Total = pod.Count * p.Price,
                    UserId = od.UserId
                }).ToList();

                ViewBag.Total = (from dbv in dashboardView
                                 select dbv.Total).Sum();

                return(View(dashboardView));
            }
            else
            {
                var dashboardView = (from o in orders
                                     join od in orderDetails on o.OrderId equals od.OrderId
                                     join pod in productOrderDetails on od.OrderDetailId equals pod.OrderDetailId
                                     join p in products on pod.ProductId equals p.ProductId
                                     join pt in productTypes on p.ProductTypeId equals pt.ProductTypeId
                                     where od.Paid == true
                                     select new DashboardViewModel()
                {
                    OrderID = o.OrderId,
                    StartTime = o.StarTime.ToString(),
                    EndTime = o.EndTime.ToString(),
                    ProductName = p.Name,
                    Count = pod.Count,
                    Price = p.Price,
                    Total = pod.Count * p.Price,
                    UserId = od.UserId
                }).ToList();

                ViewBag.Total = (from dbv in dashboardView
                                 select dbv.Total).Sum();

                return(View(dashboardView));
            }
        }
        public IActionResult Index(int id, int pid)
        {
            var products            = productRepository.Gets().ToList();
            var orderDetails        = orderDetailRepository.Gets().ToList();
            var orders              = orderRepository.Gets().ToList();
            var productOrderDetails = productOrderDetailRepository.Gets().ToList();
            var productTypes        = productTypeRepository.Gets().ToList();

            ViewBag.Types         = productTypes;
            ViewBag.ProductTypeID = pid;
            ViewBag.Orders        = orders;
            ViewBag.Products      = products;
            if (id != 0)
            {
                var checkOrderId = (from od in orders
                                    where od.OrderId == id
                                    select od.OrderId).FirstOrDefault();
                if (checkOrderId != 0)
                {
                    ViewBag.OrderUse = orderRepository.Get(id).Using;
                    ViewBag.TableID  = checkOrderId;
                    var newOrderView = new List <OrderViewModel>();
                    newOrderView = (from o in orders
                                    join od in orderDetails on o.OrderId equals od.OrderId
                                    join pod in productOrderDetails on od.OrderDetailId equals pod.OrderDetailId
                                    join p in products on pod.ProductId equals p.ProductId
                                    where od.OrderId == id && od.Paid == false
                                    select new OrderViewModel()
                    {
                        Name = p.Name,
                        Price = p.Price,
                        Count = pod.Count,
                        Total = p.Price * pod.Count,
                        PodId = pod.ProductOrderDetailId,
                        OrderId = od.OrderId,
                        StartTime = o.StarTime
                    }).ToList();
                    ViewBag.Sum = newOrderView.AsEnumerable().Sum(t => t.Total);
                    var checkOrderUsing = (from od in orders
                                           where od.OrderId == id
                                           select od.Using).FirstOrDefault();
                    if (checkOrderUsing)
                    {
                        ViewBag.StartTime = (from nod in newOrderView
                                             where nod.OrderId == id
                                             select nod.StartTime).FirstOrDefault().ToString("hh:mm:ss");
                    }
                    else
                    {
                        ViewBag.StartTime = null;
                    }

                    return(View(newOrderView));
                }
                else
                {
                    return(Redirect("https://localhost:44366/"));
                }
            }
            return(View());
        }