//GET  /Customer/Choose
        /// <summary>
        /// Display a list of all customers that you can search by name
        /// </summary>
        /// <param name="repo">The repository of info, pulled from DB</param>
        /// <param name="searchString">Filters list of customers to only the ones with the searchString in their name</param>
        /// <returns></returns>
        public ActionResult Choose([FromServices] IDbRepository repo, string searchString)
        {
            /* List of customers as CustomerViewModel in an IEnumerable*/
            List <CustomerViewModel> allCustomers = new List <CustomerViewModel>();

            foreach (var c in repo.GetCustomers().ToList())
            {
                //ensure it's been loaded
                if (c.CustomerOrderHistory.Count() == 0)
                {
                    repo.GetOrderHistory(c);
                }

                allCustomers.Add(StoreToViewMapper.MapCustomerToView(c));
            }

            //filtered by search string
            if (!string.IsNullOrEmpty(searchString))
            {
                allCustomers = allCustomers.Where(
                    cust => cust.Name.Contains(searchString)).ToList();
            }

            return(View(allCustomers));
        }
        // GET: OrderController
        public ActionResult Index([FromServices] IDbRepository repo, string store, string customer)
        {
            IEnumerable <IOrder>  repoorders = repo.GetAllOrders().ToList();
            List <OrderViewModel> orders     = new List <OrderViewModel>();

            //convert to view model
            if (repoorders.Count() > 0)
            {
                foreach (var order in repoorders)
                {
                    OrderViewModel orderViewModel = StoreToViewMapper.MapOrderToViewModel(order);
                    orders.Add(orderViewModel);
                }
            }

            //filter by customer and/or store
            if (!string.IsNullOrWhiteSpace(store))
            {
                _logger.LogInformation($"Loading orders for {store}");
                orders = orders.Where(order => order.StoreName.Contains(store)).ToList();
            }

            if (!string.IsNullOrWhiteSpace(customer))
            {
                _logger.LogInformation($"Loading orders for {store}");
                orders = orders.Where(order => order.Name.Contains(customer)).ToList();
            }

            return(View(orders));
        }
Exemple #3
0
        /// <summary>
        /// Get's the data needed by the Stores action.
        /// </summary>
        /// <param name="repo"></param>
        /// <returns>List of all stores</returns>
        private static List <StoreViewModel> LoadandRetrieveStoreData(IDbRepository repo)
        {
            List <StoreViewModel> stores = new List <StoreViewModel>();

            foreach (var x in repo.GetLocations().ToList())
            {
                repo.GetOrderHistory(x);

                stores.Add(StoreToViewMapper.MapLocationToStore(x));
            }

            return(stores);
        }
        // GET: Customer/Edit/5
        public ActionResult Edit([FromServices] IDbRepository repo, string customerName)
        {
            CustomerViewModel customerViewModel = null;

            if (string.IsNullOrWhiteSpace(customerName))
            {
                _logger.LogError("Bad Customer Name given.");
                return(View(nameof(Choose)));
            }
            else
            {
                customerViewModel = StoreToViewMapper.MapCustomerToView(
                    repo.GetCustomerByName(new Name(customerName))
                    );
            }


            ViewData["Stores"] = GetStoreNames(repo);
            return(View(customerViewModel ?? new CustomerViewModel()));
        }
Exemple #5
0
        //GET: Store/Details?&store=store
        public ActionResult Details([FromServices] IDbRepository repo, string store)
        {
            if (!string.IsNullOrWhiteSpace(store))
            {
                var s = repo.GetLocation(store);

                if (s.LocationOrderHistory.Count() == 0)
                {
                    repo.GetOrderHistory(s);
                }

                var viewModel = StoreToViewMapper.MapLocationToStore(s);

                return(View(viewModel));
            }
            else
            {
                ModelState.AddModelError("BadName", "Bad store name given");
                return(RedirectToAction("Stores"));
            }
        }
Exemple #6
0
        public ActionResult Stock([FromServices] IDbRepository repo, string store)
        {
            if (!string.IsNullOrWhiteSpace(store))
            {
                Store.Location            modelLocation = repo.GetLocation(store);
                List <StockItemViewModel> stocks        = new List <StockItemViewModel>();

                foreach (var item in modelLocation.GetAllStock())
                {
                    stocks.Add(StoreToViewMapper.MapStockToStockItem(item));
                }

                return(View(stocks));
            }
            else
            {
                _logger.LogError("Error: bad store name given.");
                ModelState.TryAddModelError("BadStore", "Error: bad store name given.");
                return(View(nameof(Stores), LoadandRetrieveStoreData(repo)));
            }
        }
        // GET: Customer/Details/5
        // view order history and other details
        public ActionResult Details([FromServices] IDbRepository repo, string customerName)
        {
            if (string.IsNullOrWhiteSpace(customerName))
            {
                //todo: set error thing to display on the view, could not find customer
                ModelState.TryAddModelError("customerName", "Invalid name given, it's null, or just space");
                _logger.Log(LogLevel.Error, "Invalid name given, it's null, or just space");
                return(RedirectToAction(nameof(Choose)));
            }
            else
            {
                Store.Customer c = repo.GetCustomerByName(new Name(customerName));

                /* get the order history from the repo into the model
                 * incase a new one has been placed since the model was loaded.
                 * Utilized in the mapper to fill in the object.
                 */
                repo.GetOrderHistory(c);

                CustomerViewModel customer = StoreToViewMapper.MapCustomerToView(c);

                return(View(customer));
            }
        }