public Product getProduct(int id) { using CrmDbContext db = new CrmDbContext(); ProductManagement prodMangr = new ProductManagement(db); return(prodMangr.FindProductById(id)); }
static void Main2() { ProductOption prod = new ProductOption { Name = "mobile", Price = 300, Quantity = 5, }; using CrmDbContext db = new CrmDbContext(); ProductManagement prodMangr = new ProductManagement(db); // product tries Product prodFind = prodMangr.FindProduct(2); Console.WriteLine( $"Id= {prodFind.Id} Name= {prodFind.Name} Price= {prodFind.Price}" + $" Quantity= {prodFind.Quantity}"); //testing reading a customer Product pd3 = prod.FindProductById(2); Console.WriteLine( $"Id= {pd3.Id} Name= {pd3.Name} Price= {pd3.Price} Quantity={pd3.Quantity}"); //testing updating ProductOption prodUpdateName = new ProductOption { Name = "laptop" }; Product product = prodMangr.Update(prodChangingName, 2); pd3 = product; Console.WriteLine( $"Id= {pd3.Id} Name= {pd3.Name} Price= {pd3.Price} Quantity= {pd3.Quantity}"); //testing deletion bool result = prodMangr.DeleteProductById(3); Console.WriteLine($"Result = {result}"); pd3 = prodMangr.FindProductById(3); if (pd3 != null) { Console.WriteLine( $"Id= {pd3.Id} Name= {pd3.Name} Price= {pd3.Price} Quantity= {pd3.Quantity}"); } else { Console.WriteLine("The product does not exist"); } }
private static void ReadProduct(ProductManagement prodMangr) { Product pr = prodMangr.FindProductById(2); if (pr != null) { Console.WriteLine( $"Id={pr.Id} ProductName={pr.ProductName} Price={pr.Price} Quantity={pr.Quantity} TotalCost={pr.TotalCost}"); } else { Console.WriteLine("Not Found"); } }
private static void DeleteProduct(ProductManagement prodMangr) { bool resultP = prodMangr.DeleteProductById(2); Console.WriteLine($"Result = {resultP}"); Product pd2 = prodMangr.FindProductById(2); if (pd2 != null) { Console.WriteLine( $"Id= {pd2.Id} ProductName= {pd2.ProductName} Price= {pd2.Price} Quantity = {pd2.Quantity}"); } else { Console.WriteLine("Product Not Found"); } }