public void AddItemToBasket(ClothesShopContext db, int itemId) { var existantBasketItem = BasketItems.FirstOrDefault(b => b.ClothingItem == db.ClothingItems.First(c => c.ClothingItemId == itemId).Name&& b.Size == Size); if (existantBasketItem != null) { existantBasketItem.Quantity += Quantity; existantBasketItem.Amount = (int)db.ClothingItems.First(c => c.ClothingItemId == itemId).Price *existantBasketItem.Quantity; Console.Clear(); Console.WriteLine($"{existantBasketItem.ClothingItem} ({Size}) Qty:{Quantity} added to basket"); } else { BasketItems.Add(new BasketItem() { ClothingItem = db.ClothingItems.First(c => c.ClothingItemId == itemId).Name, Size = Size, Quantity = Quantity, Amount = (int)db.ClothingItems.First(c => c.ClothingItemId == itemId).Price *Quantity } ); Console.Clear(); Console.WriteLine($"{BasketItems[BasketItems.Count() - 1].ClothingItem} ({Size}) Qty:{Quantity} added to basket"); } }
public int GetItemToUpdateNo() { Console.WriteLine("Please provide the item number for updating"); int itemToUpdate = GeneralStaticClass.ReadIntNumber(); while (BasketItems.Count() < itemToUpdate || itemToUpdate <= 0) { Console.WriteLine("Invalid choice"); itemToUpdate = GeneralStaticClass.ReadIntNumber(); } Console.WriteLine(itemToUpdate--); return(itemToUpdate--); }
public decimal TotalPrice() { var PriceBeforeDiscount = BasketItems.Select(i => i.UnitPrice).First() * BasketItems.Count(); var DiscountedPrice = PriceBeforeDiscount; if (HarryPotterBookCount() > 0) { return(DiscountedPrice = ((BasketItems.Count() - HarryPotterBookCount()) * BasketItems.Select(i => i.UnitPrice).First()) + ((BasketItems.Select(i => i.UnitPrice).First() * HarryPotterBookCount()) - ((BasketItems.Select(i => i.UnitPrice).First() * HarryPotterBookCount()) * (Discount / 100)))); } return(DiscountedPrice); }
public void DeleteItem() { Console.Clear(); Console.WriteLine("BASKET VIEW"); ShowBasket(); Console.WriteLine(); Console.WriteLine("Please provide the item number for deletion"); Console.WriteLine($"To delete all items, write {BasketItems.Count() + 1}"); int itemToDelete = GeneralStaticClass.ReadIntNumber(); while (BasketItems.Count() + 1 < itemToDelete || itemToDelete < 0) { Console.WriteLine("Invalid choice"); itemToDelete = GeneralStaticClass.ReadIntNumber(); } if (itemToDelete == BasketItems.Count() + 1) { BasketItems.Clear(); } else { BasketItems.RemoveAt(itemToDelete - 1); } }
public decimal BasketItemCount() { return(BasketItems.Count()); }