public async Task <ActionResult <CustomerDashboard> > GetDashboardDataForOwner(int id) { var dashboard = new CustomerDashboard(); var activeShops = _db.Shops.Where(x => x.UserId == id && x.IsVerified == true).Count(); var deativeShops = _db.Shops.Where(x => x.UserId == id && x.IsVerified == false).Count(); var productscount = 0; var orderCount = 0; var Product = await(from Products in _db.Products join shop in _db.Shops on Products.ShopId equals shop.Id where shop.UserId == id group new { Products, shop } by new { Products.Id } into products select new CustomerDashboard() { Products = products.Count() }).ToListAsync(); if (activeShops != 0) { var activeShopss = _db.Shops.Where(x => x.UserId == id && x.IsVerified == true).Include(x => x.Products).ToList(); foreach (var shop in activeShopss) { productscount += shop.Products.Count(); } } var orders = await(from shop in _db.Shops join order in _db.Orders on shop.Id equals order.ShopId where shop.UserId == id && order.OrderStatus == 0 select new Order() { Id = order.Id }).ToListAsync(); foreach (var order in orders) { orderCount += 1; } dashboard.ActiveShops = activeShops; dashboard.DeactiveShops = deativeShops; dashboard.Products = productscount; dashboard.NewOrders = orderCount; return(dashboard); }
public IList <CustomerDashboard> GetCustomerDashboards() { var customerDetailsList = this.container.GetItemLinqQueryable <CustomerDetails>(true).Where(customerDetail => customerDetail.Status != StatusType.Served).AsQueryable().ToList(); int bankTransactionServiceQueue = 0; int bankGeneralServiceQueue = 0; List <CustomerDashboard> customerDashboards = new List <CustomerDashboard>(); foreach (var items in customerDetailsList) { var customerTokenDashboards = new CustomerDashboard { Counter = items.Counter, TokenNumber = items.TokenNumber, ServiceType = items.ServiceType }; if (items.Status == StatusType.Inqueue) { if (items.ServiceType == ServiceType.BankTransactionService) { ++bankTransactionServiceQueue; customerTokenDashboards.EstimatedWaitingTime = 5 * bankTransactionServiceQueue; } if (items.ServiceType == ServiceType.BankGeneralService) { ++bankGeneralServiceQueue; customerTokenDashboards.EstimatedWaitingTime = 25 * bankGeneralServiceQueue; } } customerDashboards.Add(customerTokenDashboards); } return(customerDashboards); }
public ActionResult DistributorScreen() { int userId = Convert.ToInt32(Session["UserId"].ToString()); if (constr.ToLower().StartsWith("metadata=")) { EntityConnectionStringBuilder RefineConStr = new EntityConnectionStringBuilder(constr); constr = RefineConStr.ProviderConnectionString; } String sql = "SELECT * FROM (SELECT TOP (10) (dbo.Employees.EPF +' - '+dbo.Employees.CallingName) AS Customer, dbo.Items.ItemName AS Item, dbo.ItemPurchase.UnitPrice, dbo.ItemPurchase.Quantity, " + "dbo.ItemPurchase.UnitPrice* dbo.ItemPurchase.Quantity AS Total, ROW_NUMBER() OVER(PARTITION BY dbo.Employees.EPF ORDER BY dbo.ItemPurchase.ID, dbo.Employees.EPF DESC)RN " + "FROM dbo.ItemPurchase INNER JOIN " + "dbo.Employees ON dbo.ItemPurchase.EmployeeId = dbo.Employees.ID INNER JOIN " + "dbo.Items ON dbo.ItemPurchase.ItemId = dbo.Items.ID " + "WHERE (dbo.ItemPurchase.CashierId = " + userId + ") " + "ORDER BY dbo.ItemPurchase.ID DESC) t1 WHERE RN <= 20"; var model = new List <CustomerDashboard>(); using (SqlConnection con = new SqlConnection(constr)) { con.Open(); SqlCommand cmd = new SqlCommand(sql, con); SqlDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { var dashboard = new CustomerDashboard(); dashboard.Customer = dr["Customer"].ToString(); dashboard.Item = dr["Item"].ToString(); dashboard.UnitPrice = dr["UnitPrice"].ToString(); dashboard.Quantity = dr["Quantity"].ToString(); dashboard.Total = dr["Total"].ToString(); model.Add(dashboard); } } return(View(model)); }