private ProductRow creteNewProductRow(ProductRow newProductRow, ProductRow row, string key, string unitPrice) { newProductRow.ValidUntil = row.ValidFrom; ProductRow productRowNew = new ProductRow(); productRowNew.MarketId = key; productRowNew.ValidFrom = row.ValidUntil; productRowNew.ValidUntil = DateTime.MaxValue.ToString(); productRowNew.UnitPrice = unitPrice; return(productRowNew); }
public Dictionary <string, List <ProductRow> > addValuesToListList(List <List <string> > matchingValues, Dictionary <string, List <ProductRow> > dictonary) { foreach (List <string> list in matchingValues) { ProductRow productRow = new ProductRow(); productRow.MarketId = list[0]; productRow.CurrencyCode = list[1]; productRow.ValidFrom = list[2]; productRow.ValidUntil = list[3]; productRow.UnitPrice = roundPrice(list[4]); dictonary[list[0]].Add(productRow); } return(dictonary); }
public Dictionary <string, List <ProductRow> > setProductsList(Dictionary <string, List <ProductRow> > list, List <string> allMarketId) { Boolean isNull; string unitPrice = null; Dictionary <string, List <ProductRow> > newItems = new Dictionary <string, List <ProductRow> >(); for (int j = 0; j < list.Count; j++) { KeyValuePair <string, List <ProductRow> > entry = list.ElementAt(j); isNull = false; for (int i = 0; i < entry.Value.Count; i++) { if (checkIfNull(entry.Value[i].ValidUntil)) { isNull = true; unitPrice = entry.Value[i].UnitPrice; entry.Value[i].ValidUntil = DateTime.MaxValue.ToString(); } if (i > 0) { int index = i - 1; if (checkIfNull(entry.Value[index].ValidUntil)) { isNull = true; unitPrice = entry.Value[index].UnitPrice; entry.Value[index].ValidUntil = DateTime.MaxValue.ToString(); } if (entry.Value[index].ValidFrom == entry.Value[i].ValidFrom && ifSmallerPrice(entry.Value[i].UnitPrice, entry.Value[index].UnitPrice)) { entry.Value.Remove(entry.Value[index]); } else if (entry.Value[index].ValidFrom == entry.Value[i].ValidFrom && ifSmallerPrice(entry.Value[index].UnitPrice, entry.Value[i].UnitPrice)) { entry.Value.Remove(entry.Value[i]); } else if (ifSmallerDate(entry.Value[i].ValidFrom, entry.Value[index].ValidUntil) && ifSmallerPrice(entry.Value[i].UnitPrice, entry.Value[index].UnitPrice)) { entry.Value[index].ValidUntil = entry.Value[i].ValidFrom; } else if (ifSmallerDate(entry.Value[i].ValidFrom, entry.Value[index].ValidUntil) && ifBiggerPrice(entry.Value[i].UnitPrice, entry.Value[index].UnitPrice)) { entry.Value.Remove(entry.Value[i]); } else if (ifBiggerDate(entry.Value[i].ValidFrom, entry.Value[index].ValidUntil) && convertToDateFormat(entry.Value[i].ValidFrom) != convertToDateFormat(entry.Value[index].ValidUntil).AddDays(1) && isNull == true) { ProductRow newProductRow = new ProductRow(); newProductRow.MarketId = entry.Key.ToString(); newProductRow.ValidFrom = entry.Value[index].ValidUntil; if (i == entry.Value.Count - 1) { ProductRow productRowNew = creteNewProductRow(newProductRow, entry.Value[i], entry.Key.ToString(), unitPrice); if (!newItems.ContainsKey(entry.Key)) { newItems[entry.Key] = new List <ProductRow>(); } newItems[entry.Key].Add(productRowNew); } else { newProductRow.ValidUntil = entry.Value[i + 1].ValidFrom; } newProductRow.UnitPrice = unitPrice; if (!newItems.ContainsKey(entry.Key)) { newItems[entry.Key] = new List <ProductRow>(); } newItems[entry.Key].Add(newProductRow); } } } } foreach (string marketId in allMarketId) { if (list.ContainsKey(marketId) && newItems.ContainsKey(marketId)) { list[marketId] = list[marketId].Concat(newItems[marketId]).ToList(); } } foreach (string marketId in allMarketId) { list[marketId] = list[marketId].Distinct().ToList(); } Dictionary <String, List <ProductRow> > newSortedList = sortLists(list); foreach (KeyValuePair <string, List <ProductRow> > entry in newSortedList) { changeValidUntil(entry.Value); } return(newSortedList); }