Esempio n. 1
0
        public bool HardDeleteCustomer(int id)
        {
            using CrmDbContext db = new CrmDbContext();
            CustomerManagement custMangr = new CustomerManagement(db);

            return(custMangr.DeleteCustomerById(id));
        }
Esempio n. 2
0
        static void Main()
        {
            AnotherMain();
            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");
            }
        }
        public static void RunCustomersCRUD()
        {
            //CustomerDataInput
            CustomerOption custOpt = new CustomerOption
            {
                FirstName = "Antonis",
                LastName  = "Gkoutzamanmis",
                Address   = "Thessaloniki",
                Email     = "*****@*****.**",
                Dob       = new DateTime(1992, 8, 4, 6, 00, 0),
            };

            //connect to the DB
            using CrmDbContext db = new CrmDbContext();
            //to using to xrisomopioume anti gia to dispose (disconnect apo vasi)

            //create a customer
            CustomerManagement custMangr = new CustomerManagement(db);
            Customer           customer  = custMangr.CreateCustomer(custOpt);

            Console.WriteLine(
                $"Id= {customer.Id} Name={customer.FirstName} Address={customer.Address} Dob={customer.Dob.Date.Day + "/"}{customer.Dob.Date.Month + "/"}{customer.Dob.Date.Year}");


            //Read Customer
            Customer cx = custMangr.FindCustomerById(2);

            if (cx != null)
            {
                Console.WriteLine(
                    $"Id={cx.Id} Name={cx.FirstName} Address={cx.Address} Dob={cx.Dob}");
            }
            else
            {
                Console.WriteLine("Customer Not Found");
            }

            //Update Customer
            CustomerOption custChangingAddress = new CustomerOption
            {
                Address = "Lamia",
            };
            Customer c2 = custMangr.Update(custChangingAddress, 1);

            Console.WriteLine(
                $"Id= {c2.Id} Name= {c2.FirstName} Address= {c2.Address}");

            //Delete Customer
            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("Customer Not Found");
            }
        }
Esempio n. 4
0
        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));
        }
Esempio n. 5
0
        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));
        }