示例#1
0
        public EditUser_Control()
        {
            InitializeComponent();

            ctx = new HardwareStoreDbContext();

            DataContext = customer;
        }
 public SubCategoryService(HardwareStoreDbContext db)
 {
     this.db = db;
 }
 public AdminUserService(HardwareStoreDbContext db)
 {
     this.db = db;
 }
示例#4
0
 public RoleStore(HardwareStoreDbContext context)
     : base(context)
 {
 }
 public ItemService(HardwareStoreDbContext db)
 {
     this.db = db;
 }
 public LocationRepository(HardwareStoreDbContext dbContext) =>
        //maybe add logger if time

        /// <summary>
        /// initializes a new customer repository given a suitable data source
        /// </summary>
        /// <param name="dbContext"></param>
        public HardwareStoreRepository(HardwareStoreDbContext dbContext) =>
        //maybe add logger if time

        /// <summary>
        /// initializes a new customer repository given a suitable data source
        /// </summary>
        /// <param name="dbContext"></param>
        public CustomerRepository(HardwareStoreDbContext dbContext) =>
示例#9
0
        public Booking_Control()
        {
            InitializeComponent();

            ctx = new HardwareStoreDbContext();
        }
示例#10
0
 public UserStore(HardwareStoreDbContext context)
     : base(context)
 {
 }
示例#11
0
 public CartManager(HardwareStoreDbContext db)
 {
     this.db    = db;
     this.carts = new ConcurrentDictionary <string, ShoppingCart>();
 }
 public ModeratorCommentService(HardwareStoreDbContext db)
 {
     this.db = db;
 }
 public ProductsRepository(HardwareStoreDbContext dbContext) =>
示例#14
0
 public ReviewService(HardwareStoreDbContext db)
 {
     this.db = db;
 }
示例#15
0
        public static void Main()
        {
            var optionsBuilder = new DbContextOptionsBuilder <HardwareStoreDbContext>();

            optionsBuilder.UseSqlServer(SecretConfiguration.ConnectionString);
            var dbContext = new HardwareStoreDbContext(optionsBuilder.Options);

            CustomerRepository customerRepository = new CustomerRepository(dbContext);
            OrderRepository    orderRepository    = new OrderRepository(dbContext);
            LocationRepository locationRepository = new LocationRepository(dbContext);
            ProductsRepository productsRepository = new ProductsRepository(dbContext);

            Console.WriteLine("Welcome to Francisco's Hardware Store! ");

            while (true)
            {
                Console.WriteLine("\no:\tPlace an order");
                Console.WriteLine("n:\tSearch for customer by name");
                Console.WriteLine("l:\tDisplay all orders by store location");
                Console.WriteLine("c:\tDisplay all orders by customer");
                Console.WriteLine("a\tView all orders that have been placed.");
                Console.WriteLine("q\tQuit");

                String input = Console.ReadLine();
                if (input == "o")
                {
                    customerRepository.DisplayCustomers();
                    Console.WriteLine("Which customer is the order for? input customer id:");
                    input = Console.ReadLine();
                    int val = 0;
                    if (Int32.TryParse(input, out val))
                    {
                        Library.Customer customer = customerRepository.GetCustomerById(Int32.Parse(input));
                        int customerId            = Int32.Parse(input);
                        Console.WriteLine("Your default store id is " + customer.DefaultStoreId + " location: " + locationRepository.GetLocationById(customer.DefaultStoreId).Name);
                        Console.WriteLine("Do you want to order from a different location? input y for yes");
                        input = Console.ReadLine();
                        if (input == "y")
                        {
                            locationRepository.DisplayLocations();
                            Console.WriteLine("input location id");
                            input = Console.ReadLine();
                            int val2 = 0;
                            if (Int32.TryParse(input, out val2))
                            {
                                int storeLoc  = Int32.Parse(input);    //storeloc will be ordering from
                                var inventory = locationRepository.GetInventoryByLocationId(storeLoc);
                                Console.WriteLine("Printing Inventory for location id " + storeLoc);
                                foreach (var inv in inventory)
                                {
                                    Console.WriteLine($"ProductId: {inv.ProductId} Amount in stock: {inv.AmountInStock} Product name: {productsRepository.GetProductByProductId(inv.ProductId).ProductName} Price {productsRepository.GetProductByProductId(inv.ProductId).Price}");
                                }
                                Console.WriteLine("Place your order.");
                                Console.WriteLine("input product id of the product you wish to buy.");
                                input = Console.ReadLine();
                                int productId = Int32.Parse(input);
                                Console.WriteLine("input amount of product you wish to buy");
                                input = Console.ReadLine();
                                int     productAmount = Int32.Parse(input);
                                decimal total         = productAmount * productsRepository.GetProductByProductId(productId).Price;

                                Console.WriteLine("Placing order...");
                                Order myOrder = new Order();
                                myOrder.OrderTime  = DateTime.Now;
                                myOrder.LocationId = storeLoc;
                                myOrder.CustomerId = customerId;
                                myOrder.OrderTotal = total;
                                orderRepository.AddOrder(myOrder);
                                orderRepository.Save();

                                Library.OrderItem myOrderItem = new Library.OrderItem();
                                myOrderItem.OrderId        = orderRepository.GetLastOrderAdded();
                                myOrderItem.OrderItemNum   = 1;
                                myOrderItem.QuantityBought = productAmount;
                                myOrderItem.ProductId      = productId;
                                myOrderItem.Price          = productsRepository.GetProductByProductId(productId).Price;
                                orderRepository.AddOrderItem(myOrderItem);
                                orderRepository.Save();

                                Console.WriteLine("OrderPlaced");
                            }
                            //Console.WriteLine("checking if input parsed"+input);
                        }
                        else
                        {
                            Console.WriteLine("Order will be placed from default location.");
                            int storeLoc  = customerRepository.GetCustomerById(customerId).DefaultStoreId;
                            var inventory = locationRepository.GetInventoryByLocationId(storeLoc);
                            Console.WriteLine("Printing Inventory for location id " + storeLoc);
                            foreach (var inv in inventory)
                            {
                                Console.WriteLine($"ProductId: {inv.ProductId} Amount in stock: {inv.AmountInStock} Product name: {productsRepository.GetProductByProductId(inv.ProductId).ProductName} Price {productsRepository.GetProductByProductId(inv.ProductId).Price}");
                            }
                            Console.WriteLine("Place your order.");
                            Console.WriteLine("input product id of the product you wish to buy.");
                            input = Console.ReadLine();
                            int productId = Int32.Parse(input);
                            Console.WriteLine("input amount of product you wish to buy");
                            input = Console.ReadLine();
                            int     productAmount = Int32.Parse(input);
                            decimal total         = productAmount * productsRepository.GetProductByProductId(productId).Price;

                            Console.WriteLine("Placing order...");
                            Order myOrder = new Order();
                            myOrder.OrderTime  = DateTime.Now;
                            myOrder.LocationId = storeLoc;
                            myOrder.CustomerId = customerId;
                            myOrder.OrderTotal = total;
                            orderRepository.AddOrder(myOrder);
                            orderRepository.Save();

                            Library.OrderItem myOrderItem = new Library.OrderItem();
                            myOrderItem.OrderId        = orderRepository.GetLastOrderAdded();
                            myOrderItem.OrderItemNum   = 1;
                            myOrderItem.QuantityBought = productAmount;
                            myOrderItem.ProductId      = productId;
                            myOrderItem.Price          = productsRepository.GetProductByProductId(productId).Price;
                            orderRepository.AddOrderItem(myOrderItem);
                            orderRepository.Save();

                            Console.WriteLine("OrderPlaced");
                            //order from default store
                        }
                    }
                    else
                    {
                        Console.WriteLine("No matches");
                    }
                }
                if (input == "n")
                {
                    do
                    {
                        Console.WriteLine("Enter first name:");
                        input = Console.ReadLine();
                    }while (input.Length == 0);

                    string input2;
                    do
                    {
                        Console.WriteLine("Enter last name: ");
                        input2 = Console.ReadLine();
                    }while (input2.Length == 0);
                    var  customerList = customerRepository.GetCustomerByName(input, input2);
                    bool flag         = customerList.Any();
                    if (!flag)
                    {
                        Console.WriteLine("no matches");
                    }
                    foreach (var c in customerList)
                    {
                        customerRepository.DisplayCustomer(c);
                    }
                }
                if (input == "l")
                {
                    bool flag = false;
                    Console.WriteLine("Do you want to see all of the details for each order? input y for yes");
                    string deets = Console.ReadLine();
                    if (deets == "y")
                    {
                        flag = true;
                    }

                    Console.WriteLine("Displaying all stores.");
                    locationRepository.DisplayLocations();

                    Console.WriteLine("Input a store id: ");
                    input = Console.ReadLine();
                    int val = 0;
                    if (Int32.TryParse(input, out val))
                    {
                        Console.WriteLine("Showing all orders for location " + input);
                        foreach (var x in locationRepository.GetOrderHistoryByLocation(Int32.Parse(input)))
                        {
                            if (flag)
                            {
                                orderRepository.DisplayOrderDetailsAll(x.OrderId);
                            }
                            else
                            {
                                orderRepository.DisplayOrderDetailsShort(x.OrderId);
                            }
                        }
                    }
                    else
                    {
                        Console.WriteLine("no matches");
                    }
                }
                if (input == "c")
                {
                    bool flag = false;
                    Console.WriteLine("Do you want to see all of the details for each order? input y for yes");
                    string deets = Console.ReadLine();
                    if (deets == "y")
                    {
                        flag = true;
                    }

                    Console.WriteLine("Displaying all customers.");
                    customerRepository.DisplayCustomers();


                    Console.WriteLine("Input a customer id: ");
                    input = Console.ReadLine();
                    int val = 0;
                    if (Int32.TryParse(input, out val))
                    {
                        Console.WriteLine("Showing all orders for customer " + input);
                        foreach (var x in customerRepository.GetOrderHistoryByCustomer(Int32.Parse(input)))
                        {
                            if (!flag)
                            {
                                orderRepository.DisplayOrderDetailsShort(x.OrderId);
                            }
                            else
                            {
                                orderRepository.DisplayOrderDetailsAll(x.OrderId);
                            }
                        }
                    }
                    else
                    {
                        Console.WriteLine("no matches");
                    }
                }
                if (input == "a")
                {
                    Console.WriteLine("Displaying all orders placed.");
                    foreach (var o in orderRepository.GetOrders())
                    {
                        Console.WriteLine("Orders" + "id: " + o.OrderId + " " + o.OrderTime + " Total: " + o.OrderTotal + " id: " + o.LocationId + o.CustomerId);
                    }
                }
                if (input == "q")
                {
                    break;
                }
            }
        }
 public OrderRepository(HardwareStoreDbContext dbContext) =>