public IActionResult Index() { if (HttpContext.Session.GetString("UserRoleId") == "2") { var totalOrders = orderService.CountOrders().GroupBy(q => q.HiddenPKId); var successfulDeliveries = deliveryService.CountDeliveries().GroupBy(q => q.Order.HiddenPKId); var cancelledOrders = orderService.CancelledOrdersforChart().GroupBy(q => q.HiddenPKId); var returnedRefundedOrders = deliveryService.ReturnedRefundedListforChart().GroupBy(q => q.Order.HiddenPKId); var products = productInventoryService.ProductList().Sum(q => q.AvailableQuantity); var profit = deliveryService.DeliveredOrderforProfit().Sum(q => (q.Order.ProductInventory.SellPrice - q.Order.ProductInventory.PurchasePrice) * q.Order.Quantity); DeliveryVM deliveryVM = new DeliveryVM() { TotalOrderVMCount = totalOrders.Count(), TotalDeliveryVMCount = successfulDeliveries.Count(), TotalAvaiableProductVMCount = products, TotalCancelledOrderVMCount = cancelledOrders.Count(), TotalReturnedRefundedOrderVMCount = returnedRefundedOrders.Count(), ProfitVM = profit / 100 }; return(View(deliveryVM)); } return(RedirectToAction("Index", "Home")); }