Example #1
0
 public static Entities.Store Map(Library.Store store) => new Entities.Store
 {
     StoreId   = store.StoreId,
     StoreLoc  = store.StoreLoc,
     PurOrder  = store.PurOrder.Select(Map).ToList(),
     Inventory = store.Inventory.Select(Map).ToList()
 };
Example #2
0
        public Library.Store GetInventory(int id)
        {
            using var context = new StoreDBContext(_contextOptions);

            // include the products and the prices in inventory
            var dbInventory = context.Inventories
                              .Include(i => i.Product)
                              .ThenInclude(i => i.Prices);

            // initialize a store with an id number
            var store = new Library.Store(id);

            // look inside dbinventory
            foreach (var inventory in dbInventory)
            {
                // wont let me do .First i'll have to ask nick why
                if (inventory.StoreId == id)
                {
                    // turn the price datatype to a list
                    var PriceList = inventory.Product.Prices.ToList();
                    // should grab the newest price in price list
                    var price = PriceList[PriceList.Count - 1].Price1;
                    // add to the Inventory class
                    store.AddInventory(new Library.Product(inventory.Product.ProductId, inventory.Product.Name, (int)inventory.Quantity, (double)price));
                }
            }
            // return this mess.
            return(store);
        }
        public void InventoryContainsTest()
        {
            var shark = new Library.Animal();

            shark.Name = "shark";
            var nyc = new Library.Store();

            nyc.Inventory = new Dictionary <Library.Animal, int>();
            nyc.AddToInventory(shark, 20);
            var actual = nyc.InInventory(shark);

            Assert.True(actual == true);
        }
Example #4
0
        public List <Library.Order> GetStoreOrders(Library.Store store)
        {
            using var context = new AquariumContext(_contextOptions);
            var dbOrders = context.Orders
                           .Where(o => o.StoreId == store.StoreId);
            var orders = new List <Library.Order>();

            foreach (var obj in dbOrders)
            {
                orders.Add(GetOrderById(obj.OrderId));
            }
            return(orders);
        }
        public void AddInventoryTestFail()
        {
            var shark = new Library.Animal();

            shark.Name = "shark";
            var nyc = new Library.Store();

            nyc.Inventory = new Dictionary <Library.Animal, int>();
            nyc.AddToInventory(shark, 0);
            var actual = nyc.InInventory(shark);

            Assert.True(actual == false);
        }
        public void RemoveFromInventoryTest2()
        {
            var penguin = new Library.Animal();

            penguin.Name = "penguin";
            var nyc = new Library.Store();

            nyc.Inventory = new Dictionary <Library.Animal, int>();
            nyc.AddToInventory(penguin, 20);
            var actual = nyc.RemoveFromInventory(penguin, 100);

            Assert.True(actual == false);
        }
Example #7
0
        public Dictionary <Library.Animal, int> GetStoreInventory(Library.Store store)
        {
            using var context = new AquariumContext(_contextOptions);
            var dbInventory = context.Inventories
                              .Where(i => i.StoreId == store.StoreId)
                              .Include(i => i.Animal)
                              .ToList();
            var appInventory = new Dictionary <Library.Animal, int>();

            foreach (var thing in dbInventory)
            {
                appInventory.Add(GetAnimalByName(thing.Animal.Name), thing.Quantity);
            }
            return(appInventory);
        }
Example #8
0
        /// <summary>
        /// Returns the order History by Store ID
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public Library.Store GetOrderHistoryOfStore(int id)
        {
            using var context = new StoreDBContext(_contextOptions);
            var dbOrderHitory = context.CustomerOrders.Include(c => c.Customer);
            var stores        = new Library.Store(id);

            foreach (var order in dbOrderHitory)
            {
                if (order.StoreId == id)
                {
                    var time = order.TransactionTime;
                    stores.AddOrder(new Order(order.TransactionNumber, id, order.CustomerId, order.Customer.FirstName, order.Customer.LastName, order.TransactionTime.ToString()));
                }
            }
            return(stores);
        }
        public void AddToInventoryTest2()
        {
            // Arrange
            var penguin = new Library.Animal();

            penguin.Name = "penguin";
            var nyc = new Library.Store();

            nyc.Inventory = new Dictionary <Library.Animal, int>();
            nyc.AddToInventory(penguin, 1555);
            // Act
            var actual = nyc.Inventory[penguin];

            // Assert
            Assert.True(actual == 1555);
        }
        public void AddToInventoryTest()
        {
            // Arrange
            var newAnimal = new Library.Animal();

            newAnimal.Name = "whale";
            var nyc = new Library.Store();

            nyc.Inventory = new Dictionary <Library.Animal, int>();
            // Act
            nyc.AddToInventory(newAnimal, 5);
            // Assert
            var actual = nyc.Inventory[newAnimal];

            Assert.True(actual == 5);
        }
        //return a list of appstores from the db
        //should be called first to populate stores
        public List <Library.Store> GetStores(List <Library.Customer> allCustomers)
        {
            using var context = new P0Context(_dbContextOptions);
            List <Library.Store> storeList = new List <Library.Store>();

            var dbStores = context.Stores
                           .Include(s => s.Items)
                           .ThenInclude(i => i.Product)
                           .Include(s => s.Orders)
                           .ThenInclude(o => o.Customer)
                           .ToList();

            //creates an appstore for each store in the db
            foreach (var dbStore in dbStores)
            {
                Library.Store appStore = new Library.Store(dbStore.Location, dbStore.Name);
                foreach (var item in dbStore.Items)
                {
                    appStore.AddItem(item.Product.Name, (int)item.Quantity);
                }
                foreach (var order in dbStore.Orders)
                {
                    //check if customer is already created
                    bool created = false;
                    foreach (var customer in allCustomers)
                    {
                        if (customer.Name == order.Customer.Name)
                        {
                            created = true;
                            appStore.AddCustomer(customer);
                            customer.AddToOrderHistory(GetOrder(order.Id, appStore, customer));
                        }
                    }
                    //if not, create new customer
                    if (!created)
                    {
                        Library.Customer newCustomer = new Library.Customer(order.Customer.Name);
                        appStore.AddCustomer(newCustomer);
                        allCustomers.Add(newCustomer);
                        newCustomer.AddToOrderHistory(GetOrder(order.Id, appStore, newCustomer));
                    }
                }
                storeList.Add(appStore);
            }
            //could return allCustomers
            return(storeList);
        }
        public int GetStoreCustomer(string customerName, Library.Store store)
        {
            //if customer has ordered from store return appCustomerid
            //return of 0 indicates customer wasnt found
            using var context = new P0Context(_dbContextOptions);
            int customerId = 0;

            var dbOrders = context.Orders
                           .Include(o => o.Customer)
                           .ToList();

            foreach (var order in dbOrders)
            {
                if (order.StoreId == store.Id && order.Customer.Name == customerName)
                {
                    customerId = (int)order.CustomerId;
                }
            }
            return(customerId);
        }
        public bool CustomerExists(string customerName, Library.Store store)
        {
            // if customer has ordered from store return true
            using var context = new P0Context(_dbContextOptions);
            bool exists = false;

            var dbOrders = context.Orders
                           .Include(o => o.Customer)
                           .ToList();

            foreach (var order in dbOrders)
            {
                if (order.StoreId == store.Id && order.Customer.Name == customerName)
                {
                    exists = true;
                }
            }

            return(exists);
        }
Example #14
0
        public Library.Store GetStoreByCity(string city)
        {
            using var context = new AquariumContext(_contextOptions);
            var dbStore = context.Stores
                          .Where(s => s.City == city)
                          .First();
            var appStore = new Library.Store()
            {
                StoreId   = dbStore.StoreId,
                City      = dbStore.City,
                Country   = dbStore.Country,
                Inventory = new Dictionary <Library.Animal, int>()
            };
            var appInv = GetStoreInventory(appStore); // Returns a dictionary with animals and their quantity in the store

            foreach (var thing in appInv)
            {
                appStore.Inventory.Add(thing.Key, thing.Value);
            }
            return(appStore);
        }
        //returns an appOrder from the db
        public Library.Order GetOrder(int orderId, Library.Store appStore, Library.Customer appCustomer)
        {
            using var context = new P0Context(_dbContextOptions);

            //create a product list for the order
            List <Library.Product> selections = new List <Library.Product>();
            var dbItems = context.Items
                          .Include(i => i.Product)
                          .Where(i => i.OrderId == orderId);

            foreach (var item in dbItems)
            {
                if (selections.Count == 0)
                {
                    selections.Add(new Library.Product(item.Product.Name, (int)item.Quantity));
                }

                for (int i = 0; i < selections.Count; ++i)
                {
                    if (item.Product.Name != selections.ElementAt(i).Name)
                    {
                        selections.Add(new Library.Product(item.Product.Name, (int)item.Quantity));
                    }
                }
            }

            //create the order
            var dbOrder = context.Orders
                          .First(x => x.Id == orderId);

            Library.Order newOrder = new Library.Order()
            {
                TargetStore = appStore,
                Orderer     = appCustomer,
                Time        = dbOrder.Time,
                Selections  = selections
            };
            return(newOrder);
        }
        /// <summary>
        /// //execute order in db and update passed Store
        /// </summary>
        /// <param name="storeChoice"></param>
        /// <param name="appOrder"></param>
        /// <returns></returns>
        public Library.Store FillOrderDb(Library.Store storeChoice, Library.Order appOrder)
        {
            using var context = new P0Context(_dbContextOptions);
            List <bool> successList      = storeChoice.FillOrder(appOrder);
            int         successListIndex = 0;

            //go ahead and grab everything
            var dbStore = context.Stores
                          .Include(s => s.Items)
                          .ThenInclude(i => i.Product)
                          .Include(s => s.Orders)
                          .ThenInclude(o => o.Customer)
                          .First(s => s.Id == storeChoice.Id);

            //get store inventory
            var dbItems = context.Items.Where(s => s.StoreId == storeChoice.Id);

            //find all items in inventory matching product.Name appOrderId then decrement quantity and update appStore
            foreach (var product in appOrder.Selections)
            {
                //find first item in dbItems that has the same name, and is an inventory
                var dbInvItem = dbItems.FirstOrDefault(i => i.Product.Name == product.Name);

                //update the db when fillOrder is successful
                if (successList.ElementAt(successListIndex)) // == appOrder.OrderId &&
                {
                    dbInvItem.Quantity -= product.Quantity;
                    context.Update(dbInvItem);
                    //storeChoice.Inventory.First(x=>x.Name == product.Name).Quantity = (int)dbInvItem.Quantity;
                }
                successListIndex++;
            }

            context.SaveChanges();
            return(storeChoice);
        }
Example #17
0
 public static Store Map(Library.Store store) => new Store
 {
     Id      = store.Id,
     Name    = store.Name,
     Address = store.Address
 };
Example #18
0
 public List <Library.Order> GetStoreOrders(Library.Store store)
 {
     return(StoreRepo.GetStoreOrders(store));
 }
Example #19
0
 public void UpdateStore(Library.Store store)
 {
     _db.Entry(_db.Store.Find(store.Id)).CurrentValues.SetValues(Mapper.Map(store));
 }
        public static void Main()
        {
            var optionsBuilder = new DbContextOptionsBuilder <PizzaOrdersContext>();

            optionsBuilder.UseSqlServer(SecretConfiguration.ConnectionString);
            var options = optionsBuilder.Options;

            var                dbContext          = new PizzaOrdersContext(options);
            UserRepository     userRepository     = new UserRepository(dbContext);
            OrderRepository    orderRepository    = new OrderRepository(dbContext);
            ProductsRepository productsRepository = new ProductsRepository(dbContext);
            AddressRepository  addressRepository  = new AddressRepository(dbContext);
            StoreRepository    storeRepository    = new StoreRepository(dbContext);

            Console.WriteLine("Welcome to Ita D'Pizza!");
            List <Order> orderAddressList = orderRepository.DisplayOrderHistoryAddress(1).ToList();

            Console.WriteLine(orderAddressList);
            List <User> userList = userRepository.GetUsers().ToList();

            bool bigLoop = true;

            while (bigLoop == true)
            {
                for (int i = 1; i < userList.Count() + 1; i++)
                {
                    User   userlist            = userList[i - 1];
                    string userFirstNameString = $"{i}: \"{userlist.firstName}\"";
                    string userLastNameString  = $"\"{userlist.lastName}\"";
                    Console.Write(userFirstNameString + " ");
                    Console.Write(userLastNameString);
                    Console.WriteLine();
                }

                Console.WriteLine("Please sign in.");
                Console.WriteLine("To exit, type 'exit' as either a first name or a last name");
                Console.Write("First Name: ");
                string signInFName = Console.ReadLine();
                Console.Write("Last Name: ");
                string signInLName = Console.ReadLine();
                if (signInFName.ToLower() == "exit" || signInLName.ToLower() == "exit")
                {
                    break;
                }
                // exception handling for not a valid sign in name
                // also include way to exit the console app

                List <User> signedInList = userRepository.GetUsersByName(signInFName, signInLName).ToList();
                User        signedIn     = signedInList[0];

                bool smallLoop = true;
                while (smallLoop == true)
                {
                    Console.WriteLine("What do you want to do?");
                    Console.WriteLine("o - place an order");
                    Console.WriteLine("u - look up a user");
                    Console.WriteLine("h - display order history");
                    Console.WriteLine("x - go back to login screen");
                    string choice = Console.ReadLine();
                    if (choice == "o")
                    {
                        List <Order> orderSuggestList = orderRepository.DisplayOrderHistoryUser(signedIn.userID).OrderByDescending(o => o.orderDate).ToList();
                        Order        orderSuggest     = orderSuggestList[0];
                        Console.WriteLine("So you want to place an order?");
                        Console.WriteLine("Your most recent order on record is ");
                        string orderSuggestID = $"\"{"Order ID: " + orderSuggest.orderID}\"";

                        string orderSuggestTotalCost = $"\"{"Total Cost: " + orderSuggest.totalCost}\"";
                        string orderSuggestStoreID   = $"\"{"Store ID: " + orderSuggest.storeId}\"";
                        Console.WriteLine(orderSuggestID);
                        Console.Write("Products ");
                        // what is there is no previous order? simple loop/conditional
                        // still need to figure out how to populate orderProducts from OrderHeader
                        List <Product> productListToPrint = orderRepository.GetProductsOfOrderByID(orderSuggest.orderID).ToList();
                        foreach (var item in productListToPrint)
                        {
                            Console.Write(item.productName + " ");
                        }
                        Console.WriteLine(orderSuggestTotalCost);
                        Console.WriteLine(orderSuggestStoreID);
                        Console.WriteLine("Would you like to resubmit this order? Type 'yes' or 'no'.");
                        string resubmit = Console.ReadLine();
                        while (!(resubmit.ToLower() == "yes" || resubmit.ToLower() == "no"))
                        {
                            Console.WriteLine("Not an available choice.");
                            Console.WriteLine("Would you like to resubmit this order? Type 'yes' or 'no'.");
                            resubmit = Console.ReadLine();
                        }
                        if (resubmit.ToLower() == "yes")
                        {
                            Order order1 = new Order();
                            order1.orderAddressID = orderSuggest.orderAddressID;
                            order1.userID         = signedIn.userID;
                            order1.totalCost      = 0;
                            order1.orderDate      = DateTime.Now;
                            order1.storeId        = orderSuggest.storeId;
                            List <Product> listOfProductsToAdd = orderRepository.GetProductsOfOrderByID(orderSuggest.orderID).ToList();
                            foreach (var item in listOfProductsToAdd)
                            {
                                order1.AddToOrder(item);
                            }
                            Console.WriteLine("Successfully recreated the order");
                            Console.WriteLine("Your order details");
                            orderRepository.InsertOrder(order1);
                            orderRepository.Save();
                            orderRepository.DisplayOrderDetailsByOrderID(orderRepository.getLastId());
                        }
                        else if (resubmit.ToLower() == "no")
                        {
                            Console.WriteLine("Okay, we will build a new order for you.");

                            // Instantiating new order with default values
                            Order order1 = new Order();
                            order1.orderAddressID = orderSuggest.orderAddressID;
                            order1.userID         = signedIn.userID;
                            order1.totalCost      = 0;
                            order1.orderDate      = DateTime.Now;
                            order1.storeId        = orderSuggest.storeId;

                            // displaying available addresses
                            Console.WriteLine("Here are our available addresses.");
                            List <Library.Address> addressList = addressRepository.GetAddresses().ToList();
                            for (int i = 1; i < addressList.Count() + 1; i++)
                            {
                                Library.Address addresslist          = addressList[i - 1];
                                string          addressIdString      = $"{i}: \"{addresslist.addressID}\"";
                                string          addressLine1String   = $"{i}: \"{addresslist.addressLine1}\"";
                                string          addressLine2String   = $"{i}: \"{addresslist.addressLine2}\"";
                                string          addressCityString    = $"{i}: \"{addresslist.city}\"";
                                string          addressStateString   = $"{i}: \"{addresslist.state}\"";
                                string          addressZipCodeString = $"{i}: \"{addresslist.zipCode}\"";
                                Console.Write(addressIdString + " ");
                                Console.Write(addressLine1String + " ");
                                Console.Write(addressLine2String + " ");
                                Console.Write(addressCityString + " ");
                                Console.Write(addressStateString + " ");
                                Console.WriteLine(addressZipCodeString);
                            }
                            // Parsing addressID choice
                            Console.WriteLine("Please type the Address ID of the address you would like the order to be delivered to.");
                            string addressAddChoice    = Console.ReadLine();
                            bool   parseSuccessAddress = Int32.TryParse(addressAddChoice, out int addressAddInt);
                            while (parseSuccessAddress == false || (parseSuccessAddress == true && addressAddInt > addressList.Count()))
                            {
                                Console.WriteLine("Not a valid choice. Please enter a valid integer.");
                                Console.WriteLine("Please type the Product ID of the product you would like to add to your order.");
                                addressAddChoice    = Console.ReadLine();
                                parseSuccessAddress = Int32.TryParse(addressAddChoice, out addressAddInt);
                            }
                            // adding choice to order
                            order1.orderAddressID = addressAddInt;

                            //////////////////////////////////////////////////////////////////////////////////////////
                            // displaying available stores
                            Console.WriteLine("Here are our available stores.");
                            List <Library.Store> storeList = storeRepository.GetStores().ToList();
                            for (int i = 1; i < addressList.Count() + 1; i++)
                            {
                                Library.Store storelist               = storeList[i - 1];
                                string        storeIDString           = $"{i}: \"{storelist.storeID}\"";
                                string        storeAddressLine1String = $"{i}: \"{storelist.sAddressLine1}\"";
                                string        storeAddressLine2String = $"{i}: \"{storelist.sAddressLine2}\"";
                                string        storeCityString         = $"{i}: \"{storelist.sCity}\"";
                                string        storeStateString        = $"{i}: \"{storelist.sState}\"";
                                string        storeZipCodeString      = $"{i}: \"{storelist.sZipCode}\"";
                                Console.Write(storeIDString + " ");
                                Console.Write(storeAddressLine1String + " ");
                                Console.Write(storeAddressLine2String + " ");
                                Console.Write(storeCityString + " ");
                                Console.Write(storeStateString + " ");
                                Console.WriteLine(storeZipCodeString);
                            }
                            // Parsing storeID choice
                            Console.WriteLine("Please type the Store ID of the store you would like to order from");
                            string storeAddChoice    = Console.ReadLine();
                            bool   parseSuccessStore = Int32.TryParse(storeAddChoice, out int storeAddInt);
                            while (parseSuccessStore == false || (parseSuccessStore == true && storeAddInt > storeList.Count()))
                            {
                                Console.WriteLine("Not a valid choice. Please enter a valid integer.");
                                Console.WriteLine("Please type the Store ID of the store you would like to order from.");
                                storeAddChoice    = Console.ReadLine();
                                parseSuccessStore = Int32.TryParse(storeAddChoice, out storeAddInt);
                            }
                            // adding choice to order
                            order1.storeId = storeAddInt;

                            ////////////////////////////////////////////////////////////////
                            // displaying available products
                            Console.WriteLine("Here are our available products.");
                            List <Product> productList = productsRepository.GetProducts().ToList();
                            for (int i = 1; i < productList.Count() + 1; i++)
                            {
                                Product productlist       = productList[i - 1];
                                string  productIdString   = $"{i}: \"{productlist.productName}\"";
                                string  productNameString = $"{i}: \"{productlist.productName}\"";
                                Console.Write(productIdString + " ");
                                Console.WriteLine(productNameString);
                            }

                            // deciding if user wants to add a product to order
                            Console.WriteLine("Would you like to add a product to your order? Type 'yes' or 'no'.");
                            string addAProduct = Console.ReadLine();
                            while (!(addAProduct.ToLower() == "yes" || addAProduct.ToLower() == "no"))
                            {
                                Console.WriteLine("Not an available choice.");
                                Console.WriteLine("Would you like to add a product to your order? Type 'yes' or 'no'.");
                                addAProduct = Console.ReadLine();
                            }

                            // adding product to order
                            if (addAProduct.ToLower() == "yes")
                            {
                                while (addAProduct.ToLower() == "yes")
                                {
                                    // getting user input for which product to add
                                    Console.WriteLine("Please type the Product ID of the product you would like to add to your order.");
                                    string productAddChoice    = Console.ReadLine();
                                    bool   parseSuccessProduct = Int32.TryParse(productAddChoice, out int productAddInt);
                                    while (parseSuccessProduct == false || (parseSuccessProduct == true && productAddInt > productList.Count()))
                                    {
                                        Console.WriteLine("Not a valid choice. Please enter a valid integer.");
                                        Console.WriteLine("Please type the Product ID of the product you would like to add to your order.");
                                        productAddChoice    = Console.ReadLine();
                                        parseSuccessProduct = Int32.TryParse(productAddChoice, out productAddInt);
                                    }
                                    Product productToAdd = productsRepository.GetProductByID(productAddInt);
                                    order1.AddToOrder(productToAdd);

                                    // logic to enable indefinite product adding
                                    Console.WriteLine("Would you like to add another product to your order? Type 'yes' or 'no'.");
                                    addAProduct = Console.ReadLine();
                                    while (!(addAProduct.ToLower() == "yes" || addAProduct.ToLower() == "no"))
                                    {
                                        Console.WriteLine("Not an available choice.");
                                        Console.WriteLine("Would you like to add another product to your order? Type 'yes' or 'no'.");
                                        addAProduct = Console.ReadLine();
                                    }
                                }

                                // Inserting, Saving and displaying order
                                orderRepository.InsertOrder(order1);
                                orderRepository.Save();
                                orderRepository.DisplayOrderDetailsByOrderID(orderRepository.getLastId());
                            }
                        }
                    }
                    else if (choice == "u")
                    {
                        Console.WriteLine("So you want to look up a user?");
                        Console.WriteLine("How do you want to look up?");
                        Console.WriteLine("n - Look up by name");
                        Console.WriteLine("i - Look up by user ID");
                        string lookUpChoice = Console.ReadLine();
                        while (!(lookUpChoice.ToLower() == "n" || lookUpChoice.ToLower() == "i"))
                        {
                            Console.WriteLine("Invalid choice. Please select either 'n' or 'i'.");
                            Console.WriteLine("How do you want to look up?");
                            Console.WriteLine("n - Look up by name");
                            Console.WriteLine("i - Look up by user ID");
                            lookUpChoice = Console.ReadLine();
                        }
                        if (lookUpChoice.ToLower() == "n")
                        {
                            Console.WriteLine("To look up by name, type the first name and last name.");
                            //Console.WriteLine("If you only want to search by first name, leave last name blank.");
                            //Console.WriteLine("If you only want to search by last name, leave first name blank.");
                            Console.Write("First Name: ");
                            string inputFirstNameSearch = Console.ReadLine();
                            Console.Write("Last Name: ");
                            string      inputLastNameSearch = Console.ReadLine();
                            List <User> returnedUsers       = userRepository.GetUsersByName(inputFirstNameSearch, inputLastNameSearch).ToList();
                            for (int i = 1; i < returnedUsers.Count() + 1; i++)
                            {
                                int    displayUserID        = returnedUsers[i - 1].userID;
                                string displayUserFirstName = returnedUsers[i - 1].firstName;
                                string displayUserLastName  = returnedUsers[i - 1].lastName;
                                Console.WriteLine(displayUserID + " " + displayUserFirstName + " " + displayUserLastName);
                            }
                        }
                        //else if (lookUpChoice.ToLower() == "i")
                        //{
                        //    Console.WriteLine("To look up by user ID, type the user ID");
                        //    Console.Write("User ID: ");
                        //    string inputUserIDSearch = Console.ReadLine();
                        //    bool parseSuccess = Int32.TryParse(inputUserIDSearch, out int userIdSearchInt);
                        //    while (parseSuccess == false)
                        //    {
                        //        Console.WriteLine("Not a valid choice. Please enter a valid integer.");
                        //        Console.WriteLine("To look up by user ID, type the user ID");
                        //        Console.Write("User ID: ");
                        //        inputUserIDSearch = Console.ReadLine();
                        //        parseSuccess = Int32.TryParse(inputUserIDSearch, out userIdSearchInt);
                        //    }
                        //}
                    }
                    else if (choice == "h")
                    {
                        Console.WriteLine("So you want to look up order history.");
                        Console.WriteLine("How do you want to look up orders?");
                        Console.WriteLine("l - location");
                        Console.WriteLine("u - user");
                        Console.WriteLine("s - sort all");
                        string lookUpChoice = Console.ReadLine();
                        while (!(lookUpChoice.ToLower() == "l" || lookUpChoice.ToLower() == "u" || lookUpChoice.ToLower() == "s"))
                        {
                            Console.WriteLine("Not a valid choice. Please type either 'l', 'u', or 's'.");
                            Console.WriteLine("How do you want to look up orders?");
                            Console.WriteLine("l - location");
                            Console.WriteLine("u - user");
                            Console.WriteLine("s - sort all");
                            lookUpChoice = Console.ReadLine();
                        }
                        if (lookUpChoice.ToLower() == "l")
                        {
                            Console.WriteLine("Please provide store ID");
                            Console.Write("Store ID: ");
                            string storeIdToLookUp = Console.ReadLine();
                            bool   parseSuccess    = Int32.TryParse(storeIdToLookUp, out int storeIdToLookUpInt);
                            while (parseSuccess == false)
                            {
                                Console.WriteLine("Not a valid choice. Please enter a valid Store ID.");
                                Console.WriteLine("Please provide Store ID");
                                Console.Write("Store ID: ");
                                storeIdToLookUp = Console.ReadLine();
                                parseSuccess    = Int32.TryParse(storeIdToLookUp, out storeIdToLookUpInt);
                            }
                            List <Order> orderHistory = orderRepository.DisplayOrderHistoryStore(storeIdToLookUpInt).ToList();
                            Console.Write("(Order ID) ");
                            Console.Write("(Order Address ID) ");
                            Console.Write("(Total Cost) ");
                            Console.Write("(Order DateTime) ");
                            Console.Write("(Order Store ID) ");
                            Console.WriteLine();
                            for (int i = 1; i < orderHistory.Count() + 1; i++)
                            {
                                Order  orderhistory         = orderHistory[i - 1];
                                string orderIdString        = $"{i}: \"{orderhistory.orderID}\"";
                                string orderAddressIdString = $"\"{orderhistory.orderAddressID}\"";
                                string orderTotalCostString = $"\"{orderhistory.totalCost}\"";
                                string orderDateTimeString  = $"\"{orderhistory.orderDate}\"";
                                string orderStoreIdString   = $"\"{orderhistory.storeId}\"";
                                Console.Write(orderIdString + " ");
                                Console.Write(orderAddressIdString + " ");
                                Console.Write(orderTotalCostString + " ");
                                Console.Write(orderDateTimeString + " ");
                                Console.Write(orderStoreIdString + " ");
                                Console.WriteLine();
                            }
                        }
                        else if (lookUpChoice.ToLower() == "u")
                        {
                            Console.WriteLine("Please provide User ID");
                            Console.Write("User ID: ");
                            string userIdToLookUp = Console.ReadLine();
                            bool   parseSuccess   = Int32.TryParse(userIdToLookUp, out int userIdToLookUpInt);
                            while (parseSuccess == false)
                            {
                                Console.WriteLine("Not a valid choice. Please enter a valid User ID.");
                                Console.WriteLine("Please provide User ID");
                                Console.Write("User ID: ");
                                userIdToLookUp = Console.ReadLine();
                                parseSuccess   = Int32.TryParse(userIdToLookUp, out userIdToLookUpInt);
                            }
                            List <Order> orderHistory = orderRepository.DisplayOrderHistoryUser(userIdToLookUpInt).ToList();
                            Console.Write("(Order ID) ");
                            Console.Write("(Order Address ID) ");
                            Console.Write("(Total Cost) ");
                            Console.Write("(Order DateTime) ");
                            Console.Write("(Order Store ID) ");
                            Console.WriteLine();
                            for (int i = 1; i < orderHistory.Count() + 1; i++)
                            {
                                Order  orderhistory         = orderHistory[i - 1];
                                string orderIdString        = $"{i}: \"{orderhistory.orderID}\"";
                                string orderAddressIdString = $"\"{orderhistory.orderAddressID}\"";
                                string orderTotalCostString = $"\"{orderhistory.totalCost}\"";
                                string orderDateTimeString  = $"\"{orderhistory.orderDate}\"";
                                string orderStoreIdString   = $"\"{orderhistory.storeId}\"";
                                Console.Write(orderIdString + " ");
                                Console.Write(orderAddressIdString + " ");
                                Console.Write(orderTotalCostString + " ");
                                Console.Write(orderDateTimeString + " ");
                                Console.Write(orderStoreIdString + " ");
                                Console.WriteLine();
                            }
                        }
                        else if (lookUpChoice.ToLower() == "s")
                        {
                            Console.WriteLine("So you want to look up all users.");
                            Console.WriteLine("How would you like to sort the results?");
                            Console.WriteLine("e - earliest first");
                            Console.WriteLine("l - latest first");
                            Console.WriteLine("c - cheapest first");
                            Console.WriteLine("x - most expensive first");
                            string lookUpSortChoice = Console.ReadLine();
                            while (!(lookUpSortChoice.ToLower() == "e" || lookUpSortChoice.ToLower() == "l" || lookUpSortChoice.ToLower() == "c" || lookUpSortChoice.ToLower() == "x"))
                            {
                                Console.WriteLine("Invalid choice. Please type either 'e', 'l' 'c', or 'x'.");
                                Console.WriteLine("How would you like to sort the results?");
                                Console.WriteLine("e - earliest first");
                                Console.WriteLine("l - latest first");
                                Console.WriteLine("c - cheapest first");
                                Console.WriteLine("x - most expensive first");
                                lookUpSortChoice = Console.ReadLine();
                            }
                            List <Order> collectionOfOrders = orderRepository.DisplayOrderHistory(lookUpSortChoice).ToList();
                            foreach (var item in collectionOfOrders)
                            {
                                Console.Write("Order ID: " + item.orderID + " ");
                                Console.Write("User ID: " + item.userID + " ");
                                Console.Write("Order Address ID: " + item.orderAddressID + " ");
                                Console.Write("Total Cost: " + item.totalCost + " ");
                                Console.Write("Order DateTime: " + item.orderDate + " ");
                                Console.Write("Store ID: " + item.storeId);
                                Console.WriteLine();
                            }
                        }
                    }
                    else if (choice == "x")
                    {
                        smallLoop = false;
                    }
                }
            }
        }
Example #21
0
 public void AddStore(Library.Store store)
 {
     _db.Add(Mapper.Map(store));
 }