Inventory Updated
Inventory Updated
CompilerServices;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
//using System.Net.NetworkInformation; //JEN: Removed
//using System.Reflection.Metadata.Ecma335; //JEN: Removed
using static ICT711_Day5_classes.ProductGarment; //JEN: Added
namespace ICT711_Day5_classes
{
public class Inventory : IInventory
{
private List<Product> products;
//JEN: Revised
public List<IProduct> this[string search]
{
get
{
List<IProduct> productsOut = new List<IProduct>();
return productsOut;
}
}
/*public Inventory()
{
products = new List<Product>();
}
public List<IProduct> this[string search]
{
get
{
return products.Where(p => p.ProductName.Contains(search)).ToList<IProduct>();
}
}
public IProduct this[int productID]
{
get
{
return products.FirstOrDefault(p => p.ProductId == productID);
}
}
Products.Add(product);
return true;
}
/*public bool AddProduct(Product product)
{
//throw new NotImplementedException();
// FIRST CODE
Product existingProduct = products.FirstOrDefault(p => p.ProductId == product.ProductId);
if (existingProduct == null)
{
throw new InvalidOperationException("Product is not in inventory.");
}
if (!existingGarment.SizePriceQuantity.ContainsKey(size) ||
existingGarment.SizePriceQuantity[size].quantity < quantity)
{
throw new ArgumentOutOfRangeException($"There is not enough quantity of size {size}");
}
else
{
if (existingProduct.Quantity < product.Quantity)
{
throw new ArgumentOutOfRangeException((existingProduct.Quantity.ToString()), $"There is not enough
quantity.");
}
if (existingProduct.Quantity == product.Quantity)
{
products.Remove(existingProduct);
}
else
{
existingProduct.Quantity -= product.Quantity;
}
}
return true;
}*/
inventory.AddProduct(product);
return inventory;
}
inventory.RemoveProduct(product);
return inventory;
}
}
}