public UnitOfWork(laptopContext context)
 {
     _context   = context;
     Product    = new ProductRepository(context);
     Cart       = new CartRepository(context);
     CartDetail = new CartDetailRepository(context);
     Promotion  = new PromotionRepository(context);
     Account    = new AccountRepository(context);
 }
 public UnitOfWork(ApplicationDbContext context)
 {
     _context   = context;
     Laptop     = new LaptopRepository(context);
     Cart       = new CartRepository(context);
     CartDetail = new CartDetailRepository(context);
     Promotion  = new PromotionRepository(context);
     User       = new UserRepository(context);
 }
示例#3
0
 public UnitOfWork(QLBHDienThoaiEntities context)
 {
     _context           = context;
     Product            = new ProductRepository(_context);
     Account            = new AccountRepository(_context);
     TypeProduct        = new TypeProductRepository(_context);
     Supplier           = new SupplierRespository(_context);
     Employee           = new EmployeeRepository(_context);
     OrderInvoice       = new OrderInvoiceRepository(_context);
     OrderInvoiceDetail = new OrderInvoiceDetailRepository(_context);
     Cart           = new CartRepository(_context);
     CartDetail     = new CartDetailRepository(_context);
     Promotion      = new PromotionRepository(_context);
     Customer       = new CustomerRepository(_context);
     BillOfSale     = new BillOfSaleRepository(_context);
     BillSaleDetail = new BillSaleDetailOfSaleRepository(_context);
     Payment        = new PaymentRepository(_context);
     Receipt        = new ReceiptRepository(_context);
     ReceiptDetail  = new ReceiptDetailRepository(_context);
     Pay            = new PayRepository(_context);
     PayDetail      = new PayDetailRepository(_context);
     Comment        = new CommentRepository(_context);
 }
        public void checkout(Customer activeCustomer)
        {
CHOOSEPAYMENT:
            Console.Clear();
            _consoleHelper.WriteHeaderToConsole("Check Out");
            var cartRepo   = new CartRepository();
            var activeCart = cartRepo.GetActiveCart(activeCustomer.CustomerId);

            if (activeCart != null)
            {
                var cartDetail = new CartDetailRepository();
                if (cartDetail.GetTotalItemsInCart(activeCart.CartId) < 1)
                {
                    _consoleHelper.ErrorMessage("Your cart is empty. Please continue shopping.");
                    (new CartController()).addProduct(activeCustomer);
                    return;
                }
                _consoleHelper.Write($"Your order total is {cartDetail.GetCartPrice(activeCart.CartId)}. Ready to purchase?\n");
                _consoleHelper.WriteExitCommand();
                var userInput = _consoleHelper.WriteAndReadFromConsole("Y/N > ");
                _consoleHelper.CheckForUserExit(userInput);

                if (userInput.ToLower() == "y")
                {
                    Console.Clear();
                    _consoleHelper.WriteHeaderToConsole("Choose Payment");
                    // get active customer payment option and show
                    var paymentRepo = new PaymentRepository();
                    var payments    = paymentRepo.GetAllPayments(activeCustomer.CustomerId);

                    if (payments.Count < 1)
                    {
                        var paymentController = new PaymentController();
                        var payment           = paymentController.RequestPayment(activeCustomer);
                        if (payment == null)
                        {
                            return;
                        }
                        ;
                        goto CHOOSEPAYMENT;
                    }
                    _consoleHelper.WriteLine("\nCustomer Payment Options:\n");
                    int counter = 1;
                    foreach (Payment payment in payments)
                    {
                        _consoleHelper.WriteLine(counter + ". " + payment.PaymentType + "  ****-****-****-" + payment.PaymentAccountNumber.ToString().Substring(payment.PaymentAccountNumber.ToString().Length - 4) + "\n");
                        counter++;
                    }

                    _consoleHelper.WriteExitCommand();

                    // read userinput
                    var paymentChoice = _consoleHelper.WriteAndReadFromConsole("Choose payment option > ");
                    if (_consoleHelper.CheckForUserExit(paymentChoice))
                    {
                        return;
                    }
                    ;
                    try
                    {
                        var intPaymentChoice = Convert.ToInt32(paymentChoice);
                        if (intPaymentChoice == counter)
                        {
                            return;
                        }
                        else if (intPaymentChoice > 0 && intPaymentChoice < counter)
                        {
                            var paymentId = payments[intPaymentChoice - 1].PaymentId;
                            // update order active to false
                            cartRepo.EditCartStatus(activeCart.CartId, paymentId);
                            _consoleHelper.WriteLine("\nYour order is complete! Press any key to return to main menu.\n");
                            _consoleHelper.ReadKey();
                            return;
                        }
                        else
                        {
                            _consoleHelper.WriteLine("Please enter a valid option.");
                            goto CHOOSEPAYMENT;
                        }
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine(ex.Message);
                        Debug.WriteLine(ex.StackTrace);
                    }
                }
                return;
            }
            _consoleHelper.WriteLine("Please add some products to your order first. Press any key to return to main menu.\n");
            _consoleHelper.ReadKey();
        }
        public void addProduct(Customer activeCustomer)
        {
SHOWPRODUCTS:
            Console.Clear();
            _consoleHelper.WriteHeaderToConsole("Add Products to Cart");
            ProductRepository repo = new ProductRepository();

            var products = repo.GetAllProducts();

            _consoleHelper.WriteLine("Opt Product               Price                        ");
            Console.ForegroundColor = ConsoleColor.DarkCyan;
            _consoleHelper.WriteLine("*********************************************************");
            Console.ForegroundColor = ConsoleColor.White;
            char spacePad = ' ';

            foreach (Product product in products)
            {
                StringBuilder productIdString = new StringBuilder();
                string        productId       = productIdString.Append(product.ProductId.ToString()).Append(".").ToString();
                _consoleHelper.WriteLine(productId.PadRight(8, spacePad).Substring(0, 4) + product.ProductName.PadRight(22, spacePad).Substring(0, 22) + "$" + product.ProductPrice.ToString().PadLeft(7, spacePad));
            }
            Console.ForegroundColor = ConsoleColor.DarkCyan;
            _consoleHelper.WriteLine("*********************************************************");
            Console.ForegroundColor = ConsoleColor.White;
            var    cartRepo      = new CartRepository();
            var    activeCart    = cartRepo.GetActiveCart(activeCustomer.CustomerId);
            string cartTotalLine = $"Total: ({cartDetail.GetTotalItemsInCart(activeCart.CartId)}) {cartDetail.GetCartPrice(activeCart.CartId)}";
            string space         = new string(' ', (56 - cartTotalLine.Length));

            _consoleHelper.WriteLine(space + cartTotalLine);
            _consoleHelper.WriteLine($"{products.Count + 1}" + ".  Save Cart and Return to Main Menu");
            _consoleHelper.WriteLine($"{products.Count + 2}" + ".  Checkout\n");
            try
            {
                var selectedProduct = Convert.ToInt32(_consoleHelper.WriteAndReadFromConsole("> "));

                if (selectedProduct >= 1 && selectedProduct <= products.Count)
                {
                    var cartDetail = new CartDetailRepository();
                    cartDetail.AddProduct(activeCart.CartId, selectedProduct, 1);
                    _consoleHelper.WriteLine("One item has been put into your cart.");
                    Thread.Sleep(500);
                    goto SHOWPRODUCTS;
                }
                else if (selectedProduct == products.Count + 1)
                {
                    return;
                }
                else if (selectedProduct == products.Count + 2)
                {
                    checkout(activeCustomer);
                }
                else
                {
                    _consoleHelper.WriteLine("Please choose a valid product number!");
                    goto SHOWPRODUCTS;
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
                Debug.WriteLine(ex.StackTrace);
                _consoleHelper.WriteLine("Please enter the numbers showed on screen!");
                Thread.Sleep(1000);
                goto SHOWPRODUCTS;
            }
        }
        static void Main(string[] args)
        {
            SplashScreen splash = new SplashScreen();

            splash.GenerateSplashScreen();
            Console.SetWindowSize(57, 35);
            Customer      activeCustomer = null;
            ConsoleHelper consoleHelper  = new ConsoleHelper();

SHOWMENU:
            {
                Console.Clear();
                consoleHelper.WriteHeaderToConsole("Welcome to Bangazon!");
                if (activeCustomer != null)
                {
                    string custString = $"Logged In As: {activeCustomer.CustomerName}";
                    string cartString = "";
                    var    cartRepo   = new CartRepository();
                    var    activeCart = cartRepo.GetActiveCart(activeCustomer.CustomerId);
                    if (activeCart == null)
                    {
                        cartRepo.AddCart(activeCustomer.CustomerId);
                        activeCart = cartRepo.GetActiveCart(activeCustomer.CustomerId);
                    }
                    else
                    {
                        var cartDetail = new CartDetailRepository();
                        cartString = $"Cart({cartDetail.GetTotalItemsInCart(activeCart.CartId)}) {cartDetail.GetCartPrice(activeCart.CartId)}";
                    }
                    string space = new string(' ', (56 - cartString.Length - custString.Length));
                    if (cartString.Length < 1)
                    {
                        consoleHelper.WriteLine($"{custString}\n");
                    }
                    else
                    {
                        consoleHelper.WriteLine($"{custString}{space}{cartString}\n");
                    }
                }
                consoleHelper.WriteLine(
                    "1.Create a new customer account" + "\n"
                    + "2.Choose an existing customer" + "\n"
                    + "3.Create a new payment option" + "\n"
                    + "4.Add product(s) to shopping cart" + "\n"
                    + "5.View Items in Cart\n"
                    + "6.Complete an order" + "\n"
                    + "7.View product popularity" + "\n"
                    + "8.Logout Current User" + "\n"
                    + "9.Leave Bangazon!");
                Console.ForegroundColor = ConsoleColor.White;
                var userInput = consoleHelper.WriteAndReadFromConsole("> ");
                switch (userInput)
                {
                case "1":
                    Console.Clear();
                    var CustomerInfo = new CustomerController();
                    activeCustomer = CustomerInfo.CreateCustomer();
                    goto SHOWMENU;

                case "2":
                    Console.Clear();
                    var selectCustomerCtrl = new SelectCustomerController();
                    activeCustomer = selectCustomerCtrl.SelectActiveCustomer();
                    break;

                case "3":
                    if (activeCustomer == null)
                    {
                        Console.Clear();
                        selectCustomerCtrl = new SelectCustomerController();
                        activeCustomer     = selectCustomerCtrl.SelectActiveCustomer();
                        if (activeCustomer == null)
                        {
                            break;
                        }
                    }
                    Console.Clear();
                    var PaymentCtrl = new PaymentController();
                    PaymentCtrl.RequestPayment(activeCustomer);
                    break;

                case "4":
                    if (activeCustomer == null)
                    {
                        Console.Clear();

                        activeCustomer = (new SelectCustomerController()).SelectActiveCustomer();
                        if (activeCustomer == null)
                        {
                            break;
                        }
                    }
                    (new CartController()).addProduct(activeCustomer);

                    break;

                case "5":
                    if (activeCustomer == null)
                    {
                        Console.Clear();

                        activeCustomer = (new SelectCustomerController()).SelectActiveCustomer();
                        if (activeCustomer == null)
                        {
                            break;
                        }
                    }
                    (new ViewCartController()).getItemsInCart(activeCustomer);

                    break;

                case "6":

                    if (activeCustomer == null)
                    {
                        Console.Clear();
                        activeCustomer = (new SelectCustomerController()).SelectActiveCustomer();
                        if (activeCustomer == null)
                        {
                            break;
                        }
                    }
                    (new CartController()).checkout(activeCustomer);
                    break;

                case "7":
                    Console.Clear();
                    var productPopularityController = new ProductPopularityController();
                    productPopularityController.DisplayPopularProducts();

                    break;

                case "8":
                    if (activeCustomer != null)
                    {
                        consoleHelper.WriteLine($"\nUser {activeCustomer.CustomerName} is being logged out!");
                        activeCustomer = null;
                        Thread.Sleep(1500);
                    }
                    else
                    {
                        consoleHelper.WriteLine($"\nNo customer currently logged in!");
                        Thread.Sleep(1500);
                    }

                    break;

                case "9":
                    Console.Clear();
                    consoleHelper.WriteHeaderToConsole("Logging out...");
                    Thread.Sleep(1500);
                    Environment.Exit(0);
                    break;

                default:
                    consoleHelper.WriteLine("please select a valid menu item...");
                    Thread.Sleep(1000);
                    break;
                }
                goto SHOWMENU;
            }
        }