예제 #1
0
        public IActionResult GetOrdersByCustomer(string Name)
        {
            if (Name is null)
            {
                return(BadRequest("Customer field was empty or null"));
            }
            var APICustomer = new CustomerApi(new Configuration {
                BasePath = "https://localhost:44368/"
            });
            var customers     = APICustomer.ApiCustomerGet();
            var foundCustomer = customers.FirstOrDefault(cust => cust.Name.Equals(Name));

            if (foundCustomer is not null)
            {
                var APIOrder = new OrderApi(new Configuration {
                    BasePath = "https://localhost:44368/"
                });
                var          orders         = APIOrder.ApiOrderGet();
                List <Order> customerOrders = orders.Where(
                    order => order.Customer.Id.Equals(foundCustomer.Id)).ToList();
                return(View(customerOrders));
            }

            ViewBag.ErrorMessage = "This user has no previous orders.";
            return(View("ViewCustomerOrders"));
        }
        public IActionResult CheckCustomerName(string Name)
        {
            if (Name is null)
            {
                return(BadRequest("Customer field was empty or null"));
            }

            var sessionOrder = Utils.GetCurrentOrder(HttpContext.Session);                          //get current session
            var API          = new CustomerApi(new Configuration {
                BasePath = "https://localhost:44368/"
            });
            var customers     = API.ApiCustomerGet();                                      //grabs list of customers from DB
            var foundCustomer = customers.FirstOrDefault(cust => cust.Name.Equals(Name));  //checks if the customer name entered already exists in the DB

            if (foundCustomer is not null)                                                 //if the user exists in the DB, apply the ID found in the DB
            {
                sessionOrder.Customer = foundCustomer;
            }
            else
            {
                sessionOrder.Customer = new Customer(Name);
            }

            //sessionOrder.Customer.Name = Name;                                             //saves customer in the session data
            Utils.SaveOrder(HttpContext.Session, sessionOrder);                                     //saves the session data for use on another page

            return(RedirectToAction("SelectStore", "FEStore"));
        }