public ProductController(IProduct product, IProductComponent productComponent, IProductMaterial productMaterial, IProductPrice productPrice) { _product = product; _productComponent = productComponent; _productMaterial = productMaterial; _productPrice = productPrice; }
public bool FindComponent(string name, ref IProductComponent component) { if (name == Name) { component = this; return(true); } else { return(false); } }
public void Setup() { _uut = new ProductCategory() { Description = "Full inventory of Bilka", Name = "Full Inventory" }; _helperProductCategory2 = new ProductCategory() { Description = "All Clothing", Name = "Clothing" }; _helperProductCategory = new ProductCategory() { Description = "All Colonial", Name = "Colonial" }; _productComponent1 = Substitute.For <IProductComponent>(); _productComponent2 = Substitute.For <IProductComponent>(); }
public bool FindComponent(string name, ref IProductComponent comp) { if (Name == name) { comp = this; return(true); } foreach (var component in ProductComponents) { if (component.FindComponent(name, ref comp)) { return(true); } } return(false); }
// https://stackoverflow.com/questions/39085721/how-to-implement-the-ienumeratort-interface-for-the-composite-pattern public IEnumerator <IProductComponent> GetEnumerator() { var components = new Stack <IProductComponent>(new[] { this }); while (components.Any()) { IProductComponent component = components.Pop(); yield return(component); if (component is ProductCategory category) { foreach (var n in category.ProductComponents) { components.Push(n); } } } }
public async Task <ActionResult> OnPostAsync([FromServices] IProductComponentFactory productComponentFactory) { if (!ModelState.IsValid) { return(Page()); } IProductComponent product = productComponentFactory.New(); WorkflowResult result = await product.SaveAsync(Product.Description); if (!result.Success) { for (int i = 0; i < result.Errors.Length; i++) { ModelState.TryAddModelError("", result.Errors[i]); } return(Page()); } return(RedirectToPage("./Details", new { id = product.ProductId })); }
public async Task <ActionResult> OnPostDeletePriceDetailAsync( [FromServices] IProductComponentFactory productComponentFactory, int priceDetailId) { try { ModelState.Clear(); if (priceDetailId <= 0) { ModelState.TryAddModelError("", "Acción Invalida"); return(Page()); } Option <IProductComponent> productResult = await productComponentFactory.CurrentAsync(Id); if (!productResult.Any()) { ModelState.TryAddModelError("", "Error, registro no existe en bd"); } IProductComponent product = productResult.Single(); WorkflowResult result = await product.DeletePriceDetailAsync(priceDetailId); if (!result.Success) { for (int i = 0; i < result.Errors.Length; i++) { ModelState.TryAddModelError("", result.Errors[i]); } } return(Page()); } finally { AditionalService = new AddAditionalServiceRequest(); Product = await _productQueryComponent.ProductAsync(Id); } }
public void AddComponent(IProductComponent root, IProductComponent component) { IProductComponent temp = null; bool found = root.FindComponent(component.Name, ref temp); if (found) { if (temp.Type == IProductComponent.ComponentType.product) { temp.Stock += component.Stock; } else if (temp.Type == IProductComponent.ComponentType.productCategory) { Debug.WriteLine("Category already exists, cannot add again"); } } else { ProductComponents.Add(component); } }
public async Task <ActionResult> OnPostAditionalServiceAsync([FromServices] IProductComponentFactory productComponentFactory) { try { ModelState.Clear(); if (!TryValidateModel(AditionalService)) { return(Page()); } Option <IProductComponent> productResult = await productComponentFactory.CurrentAsync(Id); if (!productResult.Any()) { ModelState.TryAddModelError("", "Error, registro no existe en bd"); } IProductComponent product = productResult.Single(); WorkflowResult result = await product.AddAditionalServiceAsync(AditionalService.Description, AditionalService.UnitPrice); if (!result.Success) { for (int i = 0; i < result.Errors.Length; i++) { ModelState.TryAddModelError("", result.Errors[i]); } } return(Page()); } finally { AditionalService = new AddAditionalServiceRequest(); Product = await _productQueryComponent.ProductAsync(Id); } }
public void PrintComponent(IProductComponent component) { component.Print(); }
public Printer(IProductComponent fullInventory) { _fullInventory = fullInventory; }
public ProductCustomizationDecorator(IProductComponent product) : base(product) { }
public void Remove(IProductComponent productComponent) { ProductComponents.Remove(productComponent); }
public ProductStampDecorator(IProductComponent product) : base(product) { }
public void WhenIClickToAddAProductToTheCart() { _someProduct = _productPage.GetProductComponentAtPosition(2); _someProduct.AddToCart(); }
public CrudController(IProductComponent productComponent) { _productComponent = productComponent; }
static void Main(string[] args) { string price; string name; string stock; InventoryFactory inventoryFactory = new Inventory(); IProductComponent temp = null; ConsoleKeyInfo consoleKeyInfo; IProductComponent FullInventory = inventoryFactory.Create(); Printer printerObj = new Printer(FullInventory); while (true) { Console.WriteLine(); Console.WriteLine("Bilka"); Console.WriteLine("(E)lectronics"); Console.WriteLine("(C)lothing"); Console.WriteLine("C(O)lonial"); Console.WriteLine("Total (V)alue"); Console.WriteLine("Total (S)tock"); Console.WriteLine("Specific (I)tem"); Console.WriteLine("Item with (P)rice less than"); Console.WriteLine("Item with p(R)ice more than"); Console.WriteLine("Item with S(T)ock less than"); Console.WriteLine("Item with Stoc(K) more than"); Console.WriteLine("(Q)uit"); consoleKeyInfo = Console.ReadKey(true); switch (consoleKeyInfo.Key) { case ConsoleKey.F: Console.Clear(); printerObj.PrintFullInventory(); break; case ConsoleKey.E: Console.Clear(); printerObj.PrintWithName("Electronics"); break; case ConsoleKey.C: Console.Clear(); printerObj.PrintWithName("Clothing"); break; case ConsoleKey.O: Console.Clear(); printerObj.PrintWithName("Colonial"); break; case ConsoleKey.V: Console.Clear(); printerObj.PrintTotalValue(); break; case ConsoleKey.S: Console.Clear(); printerObj.PrintTotalStock(); break; case ConsoleKey.I: Console.Clear(); Console.WriteLine("Enter product or category you want to print"); name = Console.ReadLine(); Console.WriteLine("Printing with name: " + name); printerObj.PrintWithName(name); break; case ConsoleKey.P: Console.Clear(); Console.WriteLine("Enter Price to get all items with price less than"); price = Console.ReadLine(); Console.WriteLine("Printing with price less than " + price); printerObj.PrintItemsWithPriceLessThan(Double.Parse(price)); break; case ConsoleKey.R: Console.Clear(); Console.WriteLine("Enter Price to get all items with price more than"); price = Console.ReadLine(); Console.WriteLine("Printing with price more than " + price); printerObj.PrintItemsWithPriceMoreThan(Double.Parse(price)); break; case ConsoleKey.T: Console.Clear(); Console.WriteLine("Enter stock to get all items with stock less than"); stock = Console.ReadLine(); Console.WriteLine("Printing with stock less than " + stock); printerObj.PrintItemsWithStockLessThan(Int32.Parse(stock)); break; case ConsoleKey.K: Console.Clear(); Console.WriteLine("Enter stock to get all items with stock more than"); stock = Console.ReadLine(); Console.WriteLine("Printing with stock more than " + stock); printerObj.PrintItemsWithStockLargerThan(Int32.Parse(stock)); break; case ConsoleKey.Q: Environment.Exit(1); break; } } }
public ProductComponentDecorator(IProductComponent decorated) { _decorated = decorated; }
public ProductDecorator(IProductComponent product) { _product = product; }
public HomeController(IProductComponent productComponent) { this.productComponent = productComponent ?? throw new ArgumentNullException(nameof(productComponent)); }
public void RemoveProduct(IProductComponent p) { throw new NotImplementedException(); }
public void GivenIHaveAddedAProductToTheCart() { _someProduct = _productPage.GetProductComponentAtPosition(2); _someProduct.AddToCart(); }