public VendorClothing GetVariantFromVendorClothings(List <VendorClothing> vendorClothings, Clothing clothingVariant) { // Get by type, color, and size VendorClothing vendorClothing = vendorClothings.FirstOrDefault(x => x.Clothing.GetType() == clothingVariant.GetType() && x.Clothing.Color == clothingVariant.Color && x.Clothing.Size == clothingVariant.Size); return(vendorClothing); }
private static void BuyClothing() { Clothing clothing = null; // Select clothing type Console.WriteLine("Which clothing do you want to buy?"); Console.WriteLine("1: T-Shirt: $6"); Console.WriteLine("2: Dress Shirt: $8"); clothing = SetClothingType(); // Select clothing color SetClothingColor(clothing); // Select clothing size SetClothingSize(clothing); if (vendor.Balance >= clothing.Price) { // Save the clothing for current vendor VendorClothing existingItem = _dataContext.GetVariantFromVendorClothings(vendor.VendorClothings, clothing); if (existingItem != null) { // Already have item with same type, color, size => increase quantity existingItem.Quantity++; } else { // Not existing => add new clothing.Id = (vendor.VendorClothings.Max(x => x.Clothing?.Id) ?? 0) + 1; vendor.VendorClothings.Add(new VendorClothing { Clothing = clothing, Quantity = 1 }); } // Subtract vendor's balance with the item's price vendor.Balance -= clothing.Price; // Notify Console.WriteLine("Bought successfully!"); } else { // Not enough money to buy Console.WriteLine("You don't have enough money to buy that item."); } }
private static void SellClothing() { Clothing clothing = null; // Select clothing type Console.WriteLine("Which clothing do you want to sell?"); Console.WriteLine("1: T-Shirt: $12"); Console.WriteLine("2: Dress Shirt: $20"); clothing = SetClothingType(); // Select clothing color SetClothingColor(clothing); // Select clothing size SetClothingSize(clothing); // Check if the vendor has the item in stock VendorClothing existingItem = _dataContext.GetVariantFromVendorClothings(vendor.VendorClothings, clothing); if (existingItem != null) { if (existingItem.Quantity > 1) { // More than 1 item => decrease quantity existingItem.Quantity--; } else { // Just 1 item => remove from stock vendor.VendorClothings.Remove(existingItem); } // Increase the vendor's balance with the item's retail price vendor.Balance += clothing.RetailPrice; // Notify Console.WriteLine("Sold successfully!"); } else { // Not existing => cannot sell Console.WriteLine("You don't have that item in stock to sell."); } }