public void SaveItemHistory(string currStore, CartItem currItem, string path) { using (var package = new ExcelPackage()) { List <string> storeId = currStore.Split('-').ToList(); StoreHeader storeData = StoreQuery.GetStoreHeader(Convert.ToInt64(storeId[0]), Convert.ToInt32(storeId[1])); var priceHist = HistItemQuery.GetItemHistory(currItem, storeData); var workbook = package.Workbook; var worksheet = workbook.Worksheets.Add("ItemHistory"); int currRow = 1; var dateHeadCell = worksheet.Cells[currRow, 1]; dateHeadCell.Value = "Date"; var priceHeadCell = worksheet.Cells[currRow, 2]; priceHeadCell.Value = "Price"; foreach (var record in priceHist) { currRow++; var dateCell = worksheet.Cells[currRow, 1]; dateCell.Value = record.Key.Date.ToString("dd/MM/yyyy"); var priceCell = worksheet.Cells[currRow, 2]; priceCell.Value = record.Value; } var chart = worksheet.Drawings.AddChart("chart", eChartType.ColumnStacked); var series = chart.Series.Add($"B2:B{currRow}", $"A2:A{currRow}"); series.Header = "Price"; package.SaveAs(new System.IO.FileInfo(path)); } }
public List <UpdatedCart> CalculateTotal(List <string> stores) { UpdatedCarts = new List <UpdatedCart>(); foreach (var item in stores) { List <string> storeId = item.Split('-').ToList(); StoreHeader storeData = StoreQuery.GetStoreHeader(Convert.ToInt64(storeId[0]), Convert.ToInt32(storeId[1])); UpdateCart(storeData); } return(UpdatedCarts); }
public List <UpdatedCart> CalculateTotal(List <long> chains, string location, int productsToFetch) { UpdatedCarts = new List <UpdatedCart>(); List <StoreHeader> markedStores = new List <StoreHeader>(); List <KeyValuePair <long, int> > idData = new List <KeyValuePair <long, int> >(); int uniqueFetchs; if (chains.Count >= productsToFetch) { uniqueFetchs = productsToFetch; } else { uniqueFetchs = chains.Count; } for (int i = 0; i < uniqueFetchs; i++) { idData = ItemQuery.GetCheapestStore(new List <long>() { chains[i] }, userCart.Items, location, markedStores, 1); if (idData.Count > 0) { StoreHeader storeData = StoreQuery.GetStoreHeader(idData.First().Key, idData.First().Value); UpdateCart(storeData); markedStores.Add(storeData); } } if (UpdatedCarts.Count > 0 && UpdatedCarts.Count < productsToFetch) { idData = ItemQuery.GetCheapestStore(chains, userCart.Items, location, markedStores, productsToFetch - UpdatedCarts.Count); foreach (var id in idData) { StoreHeader storeData = StoreQuery.GetStoreHeader(id.Key, id.Value); UpdateCart(storeData); } } return(UpdatedCarts.OrderBy(c => c.TotalPrice).ToList()); }
public void UpdateCart(StoreHeader storeData) { UpdatedCart currCart = new UpdatedCart(storeData.StoreId, storeData.ChainId, storeData.StoreName, storeData.ChainName); currCart.Items = userCart.Items.Select(i => new CartItem() { ItemCode = i.ItemCode, ItemType = i.ItemType, ItemName = i.ItemName, ChainId = i.ChainId, Amount = i.Amount, Price = 0 }).ToList(); foreach (CartItem item in currCart.Items) { if (item.ItemType != 0 || item.ChainId == currCart.ChainID) { item.Price = ItemQuery.GetPrice(currCart.ChainID, currCart.StoreID, item.ItemCode, item.ItemType); } } UpdatedCarts.Add(currCart); }
public List <KeyValuePair <DateTime, decimal> > GetItemHistory(CartItem currItem, StoreHeader currStore) { using (var db = new PricingContext()) { return(db.HistoryItems.Where(i => i.ItemCode == currItem.ItemCode && i.ItemType == currItem.ItemType && i.StoreID == currStore.StoreId && i.ChainID == currStore.ChainId).Select(i => new { Date = i.LastUpdateDate, Price = i.Price }).OrderBy(i => i.Date) .AsEnumerable().Select(i => new KeyValuePair <DateTime, decimal>(i.Date, i.Price)).ToList()); } }