Exemple #1
0
        public bool SoftDeleteCustomer(int id, CustomerOption custOpt)
        {
            using CrmDbContext db = new CrmDbContext();
            CustomerManagement custMangr = new CustomerManagement(db);

            return(custMangr.SoftDeleteCustomerById(id));
        }
Exemple #2
0
        public Customer PutCustomer(int id, CustomerOption custOpt)
        {
            using CrmDbContext db = new CrmDbContext();
            CustomerManagement custMangr = new CustomerManagement(db);

            return(custMangr.Update(custOpt, id));
        }
 public List <Customer> FindCustomerByName(CustomerOption custOption)
 {
     return(db.Customers
            .Where(cust => cust.LastName == custOption.LastName)// && cust.FirstName == custOption.FirstName
            .Where(cust => cust.FirstName == custOption.FirstName)
            .ToList());
 }
Exemple #4
0
        public Customer Update(CustomerOption custOption, int customerId)
        {
            Customer customer = db.Customers.Find(customerId);

            if (custOption.FirstName != null)
            {
                customer.FirstName = custOption.FirstName;
            }

            if (custOption.LastName != null)
            {
                customer.LastName = custOption.LastName;
            }

            if (custOption.Email != null)
            {
                customer.Email = custOption.Email;
            }

            if (custOption.Dob != null)
            {
                customer.Dob = custOption.Dob;
            }

            db.SaveChanges();
            return(customer);
        }
 public Customer FindCustomerByLoginDetails(CustomerOption custOption)
 {
     return(db.Customers
            .Where(c => c.Username == custOption.Username)
            .Where(c => c.Password == custOption.Password)
            .FirstOrDefault());
 }
        public CustomerOption CreateCustomer(CustomerOption customerOpt)
        {
            //if (string.IsNullOrWhiteSpace(customerOpt.FirstName) ) return null;

            //if (string.IsNullOrWhiteSpace(customerOpt.Email) ||
            // !customerOpt.Email.Contains("@")) return null;

            Customer customer = new Customer
            {
                FirstName = customerOpt.FirstName,
                LastName  = customerOpt.LastName,
                Telephone = customerOpt.Telephone,
                Email     = customerOpt.Email,
                Address   = customerOpt.Address,
                Id        = customerOpt.Id
            };

            dbContext.Customers.Add(customer);
            dbContext.SaveChanges();

            return(new CustomerOption
            {
                FirstName = customer.FirstName,
                LastName = customer.LastName,
                Telephone = customer.Telephone,
                Email = customer.Email,
                Address = customer.Address,
                Id = customer.Id
            });
        }
Exemple #7
0
        public Customer PostCustomer(CustomerOption custOpt)
        {
            using CrmDbContext db = new CrmDbContext();
            CustomerManagement custMangr = new CustomerManagement(db);

            return(custMangr.CreateCustomer(custOpt));
        }
Exemple #8
0
        private static void DacoratePatternDemo()
        {
            IBycycle myTorBike = new Touring(new NarrowWheel(24));

            Console.WriteLine(myTorBike);
            myTorBike = new CustomerOption(myTorBike);
            Console.WriteLine(myTorBike);
        }
 private static void customerOptToCustomer(CustomerOption customerOpt, Customer customer)
 {
     customer.FirstName = customerOpt.FirstName;
     customer.LastName  = customerOpt.LastName;
     customer.Address   = customerOpt.Address;
     customer.Email     = customerOpt.Email;
     customer.Telephone = customerOpt.Telephone;
 }
Exemple #10
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 Customer FindCustomerByEmail(CustomerOption custOption)
        {
            if (custOption == null)
            {
                return(null);
            }
            if (custOption.Email == null)
            {
                return(null);
            }

            return(db.Customers
                   .Where(cust => cust.Email == custOption.Email)
                   .FirstOrDefault());
        }
Exemple #12
0
 public IActionResult UpdateCustomer([FromRoute] int id)
 {
     try
     {
         CustomerOption      customerOpt = customerService.GetCustomerById(id);
         CustomerOptionModel model       = new CustomerOptionModel {
             customer = customerOpt
         };
         return(View(model));
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Exemple #13
0
        public Customer CreateCustomer(CustomerOption custOption)
        {
            Customer customer = new Customer
            {
                FirstName = custOption.FirstName,
                LastName  = custOption.LastName,
                Adress    = custOption.Adress,
                Dob       = custOption.Dob,
                Email     = custOption.Email,
                Active    = true,
                Balance   = 0
            };

            db.Customers.Add(customer);
            db.SaveChanges();
            return(customer);
        }
        public CustomerOption UpdateCustomer(CustomerOption customerOpt, int id)
        {
            Customer customer = dbContext.Customers.Find(id);

            customerOptToCustomer(customerOpt, customer);

            dbContext.SaveChanges();

            return(new CustomerOption
            {
                FirstName = customer.FirstName,
                LastName = customer.LastName,
                Telephone = customer.Telephone,
                Email = customer.Email,
                Address = customer.Address,
                Id = customer.Id
            });
        }
        public Customer CreateCustomer(CustomerOption custOption)
        {
            Customer customer = new Customer
            {
                FirstName = custOption.FirstName,
                LastName  = custOption.LastName,
                Username  = custOption.Username,
                Password  = custOption.Password,
                Email     = custOption.Email,
                Dob       = custOption.Dob,
                Phone     = custOption.Phone,
                Active    = true,
                Balance   = 0,
                Role      = "customer",
            };

            db.Customers.Add(customer);
            db.SaveChanges();

            return(customer);
        }
        //CRUD
        // create read update delete
        public Customer CreateCustomer(CustomerOption custOption)
        {
            Customer customer = new Customer
            {
                FirstName = custOption.FirstName,
                LastName  = custOption.LastName,
                Address   = custOption.Address,
                Dob       = custOption.Dob,
                Email     = custOption.Email,
                IsActive  = true,
                Balance   = 0,
            };

            //if db doesnt exist, create it
            //db.Database.EnsureCreated();

            db.Customers.Add(customer);
            db.SaveChanges();

            return(customer);
        }
        public Customer Update(CustomerOption custOption, int customerId)
        {
            Customer customer = db.Customers.Find(customerId);

            if (custOption.FirstName != null)
            {
                customer.FirstName = custOption.FirstName;
            }
            if (custOption.LastName != null)
            {
                customer.LastName = custOption.LastName;
            }
            if (custOption.Email != null)
            {
                customer.Email = custOption.Email;
            }
            if (custOption.Password != null)
            {
                customer.Password = custOption.Password;
            }
            if (custOption.Username != null)
            {
                customer.Username = custOption.Username;
            }
            if (custOption.Phone != null)
            {
                customer.Phone = custOption.Phone;
            }
            if (custOption.Dob != new DateTime())
            {
                customer.Dob = custOption.Dob;
            }

            db.SaveChanges();
            return(customer);
        }
        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");
            }
        }
 public CustomerOption UpdateCustomer(CustomerOption customerOpt, int id)
 {
     return(customerService.UpdateCustomer(customerOpt, id));
 }
        public CustomerOption AddCustomer(CustomerOption customerOpt)
        {
            CustomerOption customerOption = customerService.CreateCustomer(customerOpt);

            return(customerOption);
        }
Exemple #21
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));
        }
Exemple #22
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));
        }