public ShoppingCart CompareShoppingCart(long storeId, ShoppingCart oldShoppingCart) { ShoppingCart newShoppingCart = new ShoppingCart(storeId); List<Item> items = GetItemsByStoreId(storeId); foreach (var item in oldShoppingCart.Items) { if (item.Key.Type == "1") { var tempList = items.Where(newItem => newItem.Code == item.Key.Code).ToList(); if ((tempList != null) && (tempList.Count == 1)) { newShoppingCart.AddItem(tempList[0], item.Value); } } else { var tempList = items.Where(newItem => newItem.Name == item.Key.Name).ToList(); if ((tempList != null) && (tempList.Count == 1)) { newShoppingCart.AddItem(tempList[0], item.Value); } } } return newShoppingCart; }
public ShoppingCart GetUserShoppingCart(User user) { ShoppingCart shoppingCart = new ShoppingCart(-1); string[] lines = File.ReadAllLines(user.FileName); if(lines != null) { foreach(string line in lines) { string[] itemDetails = line.Split(','); Item item = new Item(); int amount = int.Parse(itemDetails[0]); item.Id = long.Parse(itemDetails[1]); item.Name = itemDetails[2]; item.Price = itemDetails[3]; item.Quantity = itemDetails[4]; item.UnitOfMeasure = itemDetails[5]; item.Code = itemDetails[6]; item.Type = itemDetails[7]; item.StoreId = long.Parse(itemDetails[8]); shoppingCart.AddItem(item, amount); } return shoppingCart; } return null; }