public List <Cheese> GetCartItems() { var cartItems = CartData.GetCartItems(); var returnList = new List <Cheese>(); foreach (var cartItem in cartItems) { var cheese = CheeseData.GetAllCheese().FirstOrDefault(x => x.SKU == cartItem.SKU); if (cheese == null) { continue; } returnList.Add(new Cheese() { Name = cheese.Name, Aroma = cheese.Aroma, Colour = cheese.Colour, Flavour = cheese.Flavour, PictureRef = cheese.PictureRef, Price = cheese.Price, SKU = cheese.SKU, Texture = cheese.Texture, Id = cartItem.Id, Quantity = cartItem.Quantity }); } return(returnList); }
/** * I wanted to add a better return type for these services, * something that had a response and message. But I'm unsure of what that looks like */ public bool AddToCart(Item item) { // I would make this more generic for anything more than a POC var cheese = CheeseData.GetAllCheese().FirstOrDefault(x => x.SKU == item.SKU); if (cheese == null) { return(false); } // Because of static Cheese data, this copy is needed to give the illution of more than 1 item. This would not be the case in a real app. // This felt dirty, I had to shower after this. var cartItem = new Cheese() { Name = cheese.Name, Colour = cheese.Colour, Flavour = cheese.Flavour, Aroma = cheese.Aroma, PictureRef = cheese.PictureRef, SKU = cheese.SKU, Texture = cheese.Texture, Price = cheese.Price, Quantity = item.Quantity, Id = CartData.GetCartItemCount() + 1 }; CartData.AddItemToCart(cartItem); return(true); }
public List <Cheese> GetAllCheese() { return(CheeseData.GetAllCheese()); }