public void Adding(IProduct p, int q) { IProduct t = (IProduct)p.Clone(); if (p == null) { Hvnt?.Invoke(this, new AddProdEventArgs("We haven't this product in catalog.", this.address, p.name, q)); } if (p.type == "grit" && this.type == true) { UncorAddNotify?.Invoke(this, new AddProdEventArgs("Grit products are not added to open warehouses", this.address, p.name, q)); throw new Exception("Grit products are not added to open warehouses"); } else { if (!Finder(p.SKU)) //если в листе этого товара ещё нет { t.quantity += q; this.products.Add(t); AdProdNotify?.Invoke(this, new AddProdEventArgs($"Product {p.name} added to warehouse {this.address.city} in amount {q}", this.address, p.name, q)); } else { foreach (IProduct i in this.products) { if (i.SKU == p.SKU) { i.quantity += q; AdProdNotify?.Invoke(this, new AddProdEventArgs($"More product {p.name} added to warehouse {this.address.city} in amount {q} and now = {i.quantity}", this.address, p.name, q)); } } } } }
public void Delete(IProduct p, int q) { foreach (IProduct i in this.products) { if (i.SKU == p.SKU) { i.quantity -= q; AdProdNotify?.Invoke(this, new AddProdEventArgs($"Product {p.name} deleted from warehouse {this.address.city} in amount {q} and now = {i.quantity}", this.address, p.name, q)); } else { Hvnt?.Invoke(this, new AddProdEventArgs("We haven't this product in warehouse.", this.address, p.name, q)); } } }