예제 #1
0
        static void DisplayLocationHistory(IProject0Repository projectRepository)
        {
            _io.Output("Select an Location: \n");
            var locations    = projectRepository.GetLocations();
            var locationList = locations.ToList <StoreLocation>();
            int locationId   = 0;

            while (locationId == 0)
            {
                foreach (var item in locationList)
                {
                    _io.Output(item.LocationName + "\n");
                }
                string locationInput = _io.Input();
                try
                {
                    //get store id
                    locationId = locations.First(l => l.LocationName.ToLower() == locationInput).Id;
                }
                catch (ArgumentException ex)
                {
                    _io.Output("Location Id Invalid.");
                    s_logger.Info(ex);
                    Console.WriteLine(ex.Message);
                }
            }
            var orderHistory = projectRepository.GetOrders().Where(o => o.StoreLocationId == locationId).ToList();

            foreach (var item in orderHistory)
            {
                var productName  = projectRepository.GetProductById(item.ProductId).Name;
                var customerName = projectRepository.GetCustomerById(item.CustomerId).FirstName + " " + projectRepository.GetCustomerById(item.CustomerId).LastName;
                var locationName = projectRepository.GetLocationsById(item.CustomerId).LocationName;
                _io.Output($"ID: {item.Id} Product Name: {productName} Quantity: {item.Quantity} " +
                           $" Customer Name: {customerName} \n");
            }
        }
예제 #2
0
        static void MakeOrder(Customer customer, IProject0Repository projectRepository)
        {
            _io.Output("Choose a location: \n");
            //display all locations
            var locations    = projectRepository.GetLocations();
            var locationList = locations.ToList <StoreLocation>();
            int locationId   = 0;

            while (locationId == 0)
            {
                foreach (var item in locationList)
                {
                    _io.Output(item.LocationName + "\n");
                }
                string locationInput = _io.Input();
                try
                {
                    //get store id
                    locationId = locations.First(l => l.LocationName.ToLower() == locationInput).Id;
                }
                catch (ArgumentException ex)
                {
                    _io.Output("Store name input invalid.");
                    s_logger.Info(ex);
                    Console.WriteLine(ex.Message);
                }
            }
            //display available products
            _io.Output("Choose a product: \n");
            var products      = projectRepository.GetProducts();
            var productList   = products.Where(p => p.StoreLocationId == locationId && p.Stock > 0).ToList <Product>();
            var productObject = new Product();

            while (productObject.Name == null)
            {
                foreach (var item in productList)
                {
                    _io.Output($"Name: {item.Name} Stock: {item.Stock} Price: {item.Price} \n");
                }
                var productInput = _io.Input();
                try
                {
                    productObject = productList.First(p => p.Name.ToLower() == productInput);
                }
                catch (Exception ex)
                {
                    _io.Output("Product name or Quantity input invalid. ");
                    s_logger.Info(ex);
                    Console.WriteLine(ex.Message);
                }
            }

            var quantityInput = 0;
            var quantityBool  = true;

            while (quantityBool)
            {
                _io.Output("Choose a quantity: \n");
                quantityInput = Int32.Parse(_io.Input());
                if (quantityInput > productObject.Stock)
                {
                    _io.Output("Quantity too large. \n");
                }
                else
                {
                    quantityBool = false;
                }
            }
            productObject.Stock = productObject.Stock - quantityInput;
            projectRepository.UpdateProduct(productObject);
            DateTime timeStamp = DateTime.Now;
            var      newOrder  = new Orders {
                StoreLocationId = locationId, CustomerId = customer.Id, ProductId = productObject.Id, Quantity = quantityInput
            };

            projectRepository.AddOrder(newOrder);
            projectRepository.Save();
            _io.Output("Order Complete.");
        }