public static OrdersStatViewModel Get(IUnitOfWork db, MarketplaceKeeper marketplaceManager) { var model = new OrdersStatViewModel(); var today = DateHelper.GetAppNowTime().Date; var orders = db.Orders.GetUnshippedOrders(); model.TotalOrdersCount = orders.Count; var marketplaces = marketplaceManager.GetAll(); model.Marketplaces = marketplaces.Select(m => new OrdersByMarketplaceInfo() { Market = m.Market, MarketplaceId = m.MarketplaceId, OrderCount = orders.Count(o => o.Market == m.Market && (o.MarketplaceId == m.MarketplaceId || String.IsNullOrEmpty(m.MarketplaceId))), PaidExpeditedOrderCount = orders.Count(o => o.Market == m.Market && (o.MarketplaceId == m.MarketplaceId || String.IsNullOrEmpty(m.MarketplaceId)) && ShippingUtils.IsServiceExpedited(o.InitialServiceType)), SecondDayOrderCount = orders.Count(o => o.Market == m.Market && (o.MarketplaceId == m.MarketplaceId || String.IsNullOrEmpty(m.MarketplaceId)) && (ShippingUtils.IsServiceTwoDays(o.InitialServiceType) || ShippingUtils.IsServiceNextDay(o.InitialServiceType))), }).ToList(); model.OverdueOrdersCount = orders.Count(o => o.LatestShipDate.HasValue && ShippingUtils.AlignMarketDateByEstDayEnd(o.LatestShipDate.Value, (MarketType)o.Market) < today); return(model); }