public void AddNewItemToCart(int id, int quantity) { if (this.IsLogged) { int index = ShopInformation.AvailableProducts.Find(id); if (index >= 0) { Product productToAadd = ShopInformation.AvailableProducts[index]; if (quantity > productToAadd.Quantity) { throw new ProductNotAvailableException("Sorry! There is not enough quantity.", productToAadd); } else { Product product = new Product( productToAadd.Name, productToAadd.Price, productToAadd.ProductID, quantity); this.Cart.AddProduct(product); } } } else { Console.WriteLine("This operation is not permitted. You should log on."); } }
public void AddAvailableProduct(Product product) { if (this.IsLogged) { for (int count = 0; count < ShopInformation.AvailableProducts.Length; count++) { Product currentProduct = ShopInformation.AvailableProducts[count]; if (currentProduct.Equals(product)) { throw new ArgumentException( "Invalid input! You entered existing product ID. Please choose another one!"); } } ShopInformation.AvailableProducts.Add(product); } else { Console.WriteLine("This operation is not permitted. You should log on."); } }
public void Add(Product product) { this.elements.Add(product); }
public void Remove(Product product) { this.elements.Remove(product); }
public static bool Equals(Product firstProduct, Product secondProduct) { bool isEqual = (firstProduct.ProductID == secondProduct.ProductID); return isEqual; }
public void AddProduct(Product newProduct) { this.CartList.Add(newProduct); }
public void RemoveProduct(Product product) { this.CartList.Remove(product); }
public ProductNotAvailableException(string msg, Product product) : this(msg, product, null) { }
public ProductNotAvailableException(string msg, Product product, Exception innerEx) : base(msg, innerEx) { this.Product = product; }