public static int NewOrderID()
        {
            using var context = new Project01Context(Options);
            int orderHistory = context.OrderHistory.Count();

            return(orderHistory);
        }
        public static void ChangeCustomerName(int ID)
        {
            using var context = new Project01Context(Options);
            var customer = context.Customer.Find(ID);

            Console.WriteLine("Enter a new Customer firstname: ");
            customer.FirstName = Console.ReadLine();

            while (string.IsNullOrEmpty(customer.FirstName))
            {
                Console.WriteLine("First Name can't be empty! Input your first name once more");
                customer.FirstName = Console.ReadLine();
            }

            Console.WriteLine("Enter a new Customer lastname: ");
            customer.LastName = Console.ReadLine();
            while (string.IsNullOrEmpty(customer.LastName))
            {
                Console.WriteLine("Last Name can't be empty! Input your last name once more");
                customer.LastName = Console.ReadLine();
            }


            context.SaveChanges();
        }
        public static void AddCustomerToDB()
        {
            Console.WriteLine("Enter a new Customer firstname: ");
            var firstname = Console.ReadLine();

            while (string.IsNullOrEmpty(firstname))
            {
                Console.WriteLine("First Name can't be empty! Input your first name once more");
                firstname = Console.ReadLine();
            }
            Console.WriteLine("Enter a new Customer lastname: ");
            var lastname = Console.ReadLine();

            while (string.IsNullOrEmpty(lastname))
            {
                Console.WriteLine("Last Name can't be empty! Input your last name once more");
                lastname = Console.ReadLine();
            }
            using var context = new Project01Context(Options);

            var customer = new Customer {
                FirstName = firstname, LastName = lastname
            };

            context.Customer.Add(customer);

            context.SaveChanges();
        }
Exemple #4
0
        public static int RemoveFromInventory(int ID2, int productid, int amount)
        {
            using var context = new Project01Context(Options);
            var inventory = context.Inventory
                            .FirstOrDefault(e => e.LocationId == ID2 && e.ProductId == productid);

            int a = inventory.Amount;

            inventory.Amount -= amount;


            if (inventory.Amount <= 0)
            {
                Console.WriteLine("there is not enough stock in this store's inventory to fullfill that order");
                Console.WriteLine($"You have bought out the whole stock of ProductID: [{productid}]");
                Console.WriteLine("Enter any key to Continue: ");
                Console.ReadKey(true);
                Console.Clear();
                inventory.Amount = 0;
                context.Inventory.Update(inventory);
                context.SaveChanges();
                return(a);
            }
            else
            {
                context.Inventory.Update(inventory);
                context.SaveChanges();
                return(amount);
            }
        }
Exemple #5
0
        public static string FindLocationName(int ID2)
        {
            using var context = new Project01Context(Options);
            var location = context.Location.Find(ID2);


            return($"You have Arrived at {location.Name}");
        }
Exemple #6
0
        public static void AddToOrders(int orderid, int productid, int a)
        {
            using var context = new Project01Context(Options);
            var Order = new Orders {
                Amount = a, OrderId = orderid, ProductId = productid
            };

            context.Orders.Add(Order);
            context.SaveChanges();
        }
Exemple #7
0
        public static void DisplayLocations()
        {
            using var context = new Project01Context(Options);
            List <Location> locations = context.Location
                                        .ToList();

            foreach (var location in locations)
            {
                Console.WriteLine($"[{location.LocationId}] {location.Name}: Simply {location.Address} to reach your destination");
            }
        }
        public static void DisplayCustomers()
        {
            using var context = new Project01Context(Options);
            List <Customer> customers = context.Customer
                                        .ToList();

            foreach (var customer in customers)
            {
                Console.WriteLine($"[{customer.CustomerId}] {customer.FirstName} {customer.LastName}");
            }
        }
        public static string FindCustomerName(int ID)
        {
            using var context = new Project01Context(Options);
            var customer = context.Customer.Find(ID);

            if (customer == null)
            {
                return(null);
            }

            return($"{customer.FirstName} {customer.LastName}");
        }
        public static void DisplayOrderHistoryCustomer(int ID)
        {
            using var context = new Project01Context(Options);
            var orderHistory = context.OrderHistory
                               .Where(e => e.CustomerId == ID)
                               .ToList();

            foreach (var order in orderHistory)
            {
                Console.WriteLine($"Order ID: [{order.OrderId}], Location ID: [{order.LocationId}], Date: {order.Date}, Time: {order.Time}");
            }
            ;
        }
Exemple #11
0
        public static void DisplayInventory(int ID2)
        {
            using var context = new Project01Context(Options);
            List <Inventory> inventories = context.Inventory
                                           .Include(s => s.Product)
                                           .Where(e => e.LocationId == ID2)
                                           .ToList();

            foreach (var inventory in inventories)
            {
                Console.WriteLine($"Product ID: [{inventory.ProductId}] Amount: {inventory.Amount} Cost per {inventory.Product.Name} = ${inventory.Product.Price} ");
            }
        }
        public static void DeleteUnusedOrderHistory(int ID)
        {
            using var context = new Project01Context(Options);
            var orderHistory = context.OrderHistory
                               .FirstOrDefault(e => e.OrderId == ID);


            context.OrderHistory.Remove(orderHistory);
            context.SaveChanges();

            //To prevent identity column errors this sql code must be run:
            //DBCC CHECKIDENT (OrderHistory, RESEED, 1);
            //DBCC CHECKIDENT (OrderHistory, RESEED);
        }
        public static bool CustomerList(int ID)
        {
            using var context = new Project01Context(Options);
            List <Customer> customers = context.Customer
                                        .ToList();

            foreach (var customer in customers)
            {
                if (customer.CustomerId == ID)
                {
                    return(true);
                }
            }
            return(false);
        }
        public static void AddToOrderHistory(int customerID, int locationID)
        {
            using var context = new Project01Context(Options);

            string date = DateTime.UtcNow.ToString("MM-dd-yyyy");
            string time = DateTime.Now.ToString("HH:mm");


            var orderHistory = new OrderHistory {
                CustomerId = customerID, LocationId = locationID, Date = date, Time = time
            };

            context.OrderHistory.Add(orderHistory);
            context.SaveChanges();
        }
Exemple #15
0
 public InventoryRepository(Project01Context context)
 {
     _context = context ?? throw new ArgumentNullException(nameof(context));
 }