public static void RunBasketCRUD() { //connect to the DB using CrmDbContext db = new CrmDbContext(); //to using to xrisomopioume anti gia to dispose (disconnect apo vasi) ProductOption prOpt = new ProductOption { ProductName = "apples", Price = 1.20m, Quantity = 10 }; ProductManagement prodMangr = new ProductManagement(db); Product product = prodMangr.CreateProduct(prOpt); BasketManagement baskMangr = new BasketManagement(db); BasketOption baskOption = new BasketOption { CustomerId = 3 }; Basket basket = baskMangr.CreateBasket(baskOption); BasketProductOption bskProdOpt = new BasketProductOption { BasketId = basket.Id, ProductId = 1 }; BasketProduct baskProd = baskMangr.AddProduct(bskProdOpt); //Console.WriteLine(basket.BasketProducts[0], Product.ProductName); basket.BasketProducts.ForEach(p => Console.WriteLine(p.Product.ProductName)); }
public static void Main() { //CustomerOption custOpt = new CustomerOption //{ // FirstName = "Tester222", // LastName = "Test", // Address = "TestCity", // Email = "*****@*****.**", //}; using CrmAppDbContext db = new CrmAppDbContext(); CustomerManagement custMangr = new CustomerManagement(db); ////testing the creation of a customer //Customer customer = custMangr.CreateCustomer(custOpt); //Console.WriteLine( //$"Id= {customer.CustomerId} Name= {customer.FirstName} Address= {customer.Address}"); ////testing reading a customer //customer = custMangr.FindCustomerById(2); //if (customer != null) // Console.WriteLine( // $"Id= {customer.CustomerId} Name= {customer.FirstName} Address= {customer.Address}"); ////testing updating //CustomerOption custChangingAddress = new CustomerOption //{ // Address = "Lamia" //}; //customer = custMangr.Update(custChangingAddress, 1); //Console.WriteLine( // $"Id= {customer.CustomerId} Name= {customer.FirstName} Address= {customer.Address}"); ////testing deletion //bool result = custMangr.DeleteCustomerById(2); //Console.WriteLine($"Result = {result}"); //customer = custMangr.FindCustomerById(2); //if (customer != null) //{ // Console.WriteLine( // $"Id= {customer.CustomerId} Name= {customer.FirstName} Address= {customer.Address}"); //} //else //{ // Console.WriteLine("not found"); //} ProductOption prOpt = new ProductOption { Name = "portokalia", Price = 1.20m, Quantity = 10 }; ProductManagement prodMangr = new ProductManagement(db); Product product = prodMangr.CreateProduct(prOpt); BasketManagement baskMangr = new BasketManagement(db); BasketOption baskOption = new BasketOption { CustomerId = 5 }; Basket basket = baskMangr.CreateBasket(baskOption); BasketProductOption bskProdOpt = new BasketProductOption { BasketId = basket.Id, ProductId = 1 }; //System.NullReferenceException BasketProduct baskProd = baskMangr.AddProduct(bskProdOpt); basket.BasketProducts.ForEach( baskProduct => Console.WriteLine( db.BasketProducts .Include(b => b.Product) .Where(b => b.Id == baskProduct.Id) .First() .Product.Name) ); Console.ReadLine(); }
static void Main() { CustomerOption custOpt = new CustomerOption { FirstName = "Maria", LastName = "Pentagiotissa", Address = "Athens", Email = "*****@*****.**", }; using CrmDbContext db = new CrmDbContext(); CustomerManagement custMangr = new CustomerManagement(db); // testing the creation of a customer Customer customer = custMangr.CreateCustomer(custOpt); Console.WriteLine( $"Id= {customer.Id} Name= {customer.FirstName} Address= {customer.Address}"); //testing reading a customer customer = custMangr.FindCustomerById(2); if (customer != null) { Console.WriteLine( $"Id= {customer.Id} Name= {customer.FirstName} Address= {customer.Address}"); } //testing updating CustomerOption custChangingAddress = new CustomerOption { Address = "Lamia" }; customer = custMangr.Update(custChangingAddress, 1); Console.WriteLine( $"Id= {customer.Id} Name= {customer.FirstName} Address= {customer.Address}"); //testing deletion bool result = custMangr.DeleteCustomerById(2); Console.WriteLine($"Result = {result}"); customer = custMangr.FindCustomerById(2); if (customer != null) { Console.WriteLine( $"Id= {customer.Id} Name= {customer.FirstName} Address= {customer.Address}"); } else { Console.WriteLine("not found"); } ProductOption prOpt = new ProductOption { Name = "mila", Price = 1.20m, Quantity = 10 }; ProductManagement prodMangr = new ProductManagement(db); Product product = prodMangr.CreateProduct(prOpt); BasketManagement baskMangr = new BasketManagement(db); BasketOption baskOption = new BasketOption { CustomerId = 3 }; Basket basket = baskMangr.CreateBasket(baskOption); BasketProductOption bskProdOpt = new BasketProductOption { BasketId = 1, ProductId = 1 }; BasketProduct baskProd = baskMangr.AddProduct(bskProdOpt); basket.BasketProducts.ForEach(p => Console.WriteLine(p.Product.Name)); }
static void Main2() { CustomerOption custOpt = new CustomerOption { FirstName = "John", LastName = "XCV", Adress = "Thessaloniki", Email = "*****@*****.**", }; using CrmDbContext db = new CrmDbContext(); CustomerManagement custMngr = new CustomerManagement(db); Customer customer = custMngr.CreateCustomer(custOpt); Console.WriteLine($"Id={customer.Id} Name={customer.FirstName} Adress={customer.Adress}"); Customer cx = custMngr.FindCustomerById(2); Console.WriteLine($"Id={cx.Id} Name={cx.FirstName} Adress={cx.Adress}"); CustomerOption custChangingAdress = new CustomerOption { Adress = "Lamia" }; Customer c2 = custMngr.Update(custChangingAdress, 1); Console.WriteLine($"Id={c2.Id} Name={c2.FirstName} Adress={c2.Adress}"); bool result = custMngr.DeleteCustomerById(2); Console.WriteLine($"Result={result}"); Customer cx2 = custMngr.FindCustomerById(2); if (cx2 != null) { Console.WriteLine($"Id={cx2.Id} Name={cx2.FirstName} Adress={cx2.Adress}"); } else { Console.WriteLine("Not found"); } ProductOption prOpt = new ProductOption { Name = "apples", Price = 1.20m, Quantity = 10 }; ProductManagement prodMngr = new ProductManagement(db); Product product = prodMngr.CreateProduct(prOpt); BasketManagement baskMngr = new BasketManagement(db); BasketOption baskOption = new BasketOption { CustomerId = 3 }; Basket basket = baskMngr.CreateBasket(baskOption); BasketProductOption bskProdOpt = new BasketProductOption { BasketId = basket.Id, ProductId = 1 }; BasketProduct baskProd = baskMngr.AddProduct(bskProdOpt); basket.BasketProducts.ForEach(p => Console.WriteLine(p.Product)); }