// GET: Customer
        public ActionResult Index(string searchString)
        {
            ViewData["CurrentFilter"] = searchString;

            IEnumerable <P1B.Customer> customers = CustomerRepo.GetAllCustomers();
            IEnumerable <P1B.Location> locations = LocRepo.GetAllLocations();

            if (!String.IsNullOrEmpty(searchString))
            {
                customers = customers.Where(c => c.FirstName.ToUpper().Contains(searchString.ToUpper()) ||
                                            c.LastName.ToUpper().Contains(searchString.ToUpper()));
            }

            var viewModels = customers.Select(c => new CustomerViewModel
            {
                CustomerId          = c.Id,
                FirstName           = c.FirstName,
                LastName            = c.LastName,
                DefaultLocation     = c.DefaultLocation ?? null,
                DefaultLocationName = c.DefaultLocation != null ?
                                      (locations.Single(l => l.Id == (c.DefaultLocation ?? 0))).Name : "(none)"
            }).ToList();

            return(View(viewModels));
        }
Ejemplo n.º 2
0
        // GET: Order/Details/5
        public ActionResult Details(int id)
        {
            IEnumerable <P1B.Customer>    customers  = CustomerRepo.GetAllCustomers();
            IEnumerable <P1B.Location>    locations  = LocRepo.GetAllLocations();
            List <Project1.BLL.Cupcake>   cupcakes   = CupcakeRepo.GetAllCupcakes().OrderBy(c => c.Id).ToList();
            List <Project1.BLL.OrderItem> orderItems = OrderItemRepo.GetOrderItems(id).ToList();

            Project1.BLL.Order order = OrderRepo.GetOrder(id);

            var viewModel = new OrderViewModel
            {
                OrderId      = id,
                LocationId   = order.OrderLocation,
                LocationName = locations.Single(l => l.Id == order.OrderLocation).Name,
                CustomerId   = order.OrderCustomer,
                CustomerName = customers.Single(c => c.Id == order.OrderCustomer).ReturnFullName(),
                OrderTime    = order.OrderTime,
                Locations    = LocRepo.GetAllLocations().ToList(),
                Customers    = CustomerRepo.GetAllCustomers().ToList(),
                Cupcakes     = cupcakes,
                OrderItems   = orderItems,
                OrderTotal   = OrderRepo.GetOrder(order.Id).GetTotalCost(OrderItemRepo.GetOrderItems(order.Id).ToList(),
                                                                         cupcakes.ToList())
            };

            // give the Create view values for its dropdown
            return(View(viewModel));
        }
Ejemplo n.º 3
0
        // GET: Order/Create
        public ActionResult Create()
        {
            List <Project1.BLL.Cupcake>   cupcakesTemp   = CupcakeRepo.GetAllCupcakes().OrderBy(c => c.Id).ToList();
            List <Project1.BLL.OrderItem> orderItemsTemp = new List <Project1.BLL.OrderItem>();

            foreach (var cupcake in cupcakesTemp)
            {
                cupcake.Type = Regex.Replace(cupcake.Type, "([a-z])([A-Z])", "$1 $2");
                orderItemsTemp.Add(new Project1.BLL.OrderItem
                {
                    Id        = 0,
                    OrderId   = 0,
                    CupcakeId = cupcake.Id,
                    Quantity  = null
                });
            }

            var viewModel = new OrderViewModel
            {
                Locations  = LocRepo.GetAllLocations().ToList(),
                Customers  = CustomerRepo.GetAllCustomers().ToList(),
                Cupcakes   = cupcakesTemp,
                OrderItems = orderItemsTemp
            };

            foreach (Project1.BLL.Customer customer in viewModel.Customers)
            {
                customer.FullName = customer.ReturnFullName();
            }

            // give the Create view values for its dropdown
            return(View(viewModel));
        }
        // GET: Customer/Create
        public ActionResult Create()
        {
            var viewModel = new CustomerViewModel
            {
                Locations = LocRepo.GetAllLocations().ToList()
            };

            return(View(viewModel));
        }
Ejemplo n.º 5
0
        // GET: Orders/Create
        public ActionResult Create()
        {
            var ViewModel = new OrderViewModel();

            ViewModel.Locations = LocRepo.GetAllLocations().ToList();
            ViewModel.Customers = CusRepo.GetCustomers().ToList();
            ViewModel.Products  = ProdRepo.GetAllProducts().Select(p => new ProductViewModel(p)).ToList();
            return(View(ViewModel));
        }
Ejemplo n.º 6
0
        // GET: Order/Details/5
        public ActionResult Orders(int id, string sortOrder)
        {
            ViewData["TimeSortParm"]       = String.IsNullOrEmpty(sortOrder) ? "time_desc" : "";
            ViewData["OrderTotalSortParm"] = sortOrder == "OrderTotal" ? "order_total_desc" : "OrderTotal";

            IEnumerable <P1B.Customer>  customers  = CustomerRepo.GetAllCustomers();
            IEnumerable <P1B.Location>  locations  = LocRepo.GetAllLocations();
            List <Project1.BLL.Cupcake> cupcakes   = CupcakeRepo.GetAllCupcakes().OrderBy(c => c.Id).ToList();
            IEnumerable <P1B.Order>     orders     = LocRepo.GetLocationOrderHistory(id).ToList();
            List <OrderViewModel>       viewModels = new List <OrderViewModel>();

            ViewData["LocationName"] = locations.Single(l => l.Id == id).Name;
            ViewData["LocationId"]   = id;


            switch (sortOrder)
            {
            case "time_desc":
                orders = orders.OrderByDescending(o => o.OrderTime);
                break;

            case "OrderTotal":
                orders = orders.OrderBy(o => o.GetTotalCost(OrderItemRepo.GetOrderItems(o.Id).ToList(),
                                                            cupcakes.ToList()));
                break;

            case "order_total_desc":
                orders = orders.OrderByDescending(o => o.GetTotalCost(OrderItemRepo.GetOrderItems(o.Id).ToList(),
                                                                      cupcakes.ToList()));
                break;

            default:
                orders = orders.OrderBy(o => o.OrderTime);
                break;
            }

            foreach (var order in orders)
            {
                viewModels.Add(new OrderViewModel
                {
                    OrderId      = order.Id,
                    LocationId   = order.OrderLocation,
                    LocationName = locations.Single(l => l.Id == order.OrderLocation).Name,
                    CustomerId   = order.OrderCustomer,
                    CustomerName = customers.Single(c => c.Id == order.OrderCustomer).ReturnFullName(),
                    OrderTime    = order.OrderTime,
                    Locations    = locations.ToList(),
                    Customers    = customers.ToList(),
                    Cupcakes     = cupcakes,
                    OrderItems   = OrderItemRepo.GetOrderItems(order.Id).ToList(),
                    OrderTotal   = OrderRepo.GetOrder(order.Id).GetTotalCost(OrderItemRepo.GetOrderItems(order.Id).ToList(),
                                                                             cupcakes.ToList())
                });
            }

            return(View(viewModels));
        }
        // GET: Customer/Create
        public ActionResult Create()
        {
            var viewModel = new CustomerViewModel
            {
                Locations = LocRepo.GetAllLocations().ToList()
            };

            // give the Create view values for its dropdown
            return(View(viewModel));
        }
        public ActionResult Create(P1B.Customer customer)
        {
            try
            {
                if (customer.FirstName.Length == 0 || customer.LastName.Length == 0)
                {
                    string message = "The customer must have a first and last name.";
                    TempData["ErrorMessage"] = message;
                    _logger.LogWarning(message);
                    return(RedirectToAction("Error", "Home"));
                }
                if (CustomerRepo.CheckCustomerFullNameExists(customer.ReturnFullName()))
                {
                    string message = "There is already a customer in the system with that first and last name.";
                    TempData["ErrorMessage"] = message;
                    _logger.LogWarning(message);
                    return(RedirectToAction("Error", "Home"));
                }
                int defLocation = customer.DefaultLocation ?? 0;
                if (defLocation != 0)
                {
                    bool LocationExists = LocRepo.CheckLocationExists(defLocation);
                    if (!LocationExists)
                    {
                        string message = "This location is not in the database.";
                        TempData["ErrorMessage"] = message;
                        _logger.LogWarning(message);
                        return(RedirectToAction("Error", "Home"));
                    }
                }

                // TODO: Add insert logic here
                var newCustomer = new P1B.Customer
                {
                    FirstName       = customer.FirstName,
                    LastName        = customer.LastName,
                    DefaultLocation = customer.DefaultLocation ?? null
                };

                // TODO: Add insert logic here
                CustomerRepo.AddCustomer(newCustomer);
                return(RedirectToAction(nameof(Index)));
                // TODO: Add insert logic here
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.ToString());
                return(RedirectToAction("Error", "Home"));
            }
        }
Ejemplo n.º 9
0
        public ActionResult Index(string sortOrder)
        {
            ViewData["TimeSortParm"]       = String.IsNullOrEmpty(sortOrder) ? "time_desc" : "";
            ViewData["OrderTotalSortParm"] = sortOrder == "OrderTotal" ? "order_total_desc" : "OrderTotal";

            IEnumerable <P1B.Order>    orders    = OrderRepo.GetAllOrders();
            IEnumerable <P1B.Customer> customers = CustomerRepo.GetAllCustomers();
            IEnumerable <P1B.Location> locations = LocRepo.GetAllLocations();
            IEnumerable <P1B.Cupcake>  cupcakes  = CupcakeRepo.GetAllCupcakes().OrderBy(c => c.Id);

            switch (sortOrder)
            {
            case "time_desc":
                orders = orders.OrderByDescending(o => o.OrderTime);
                break;

            case "OrderTotal":
                orders = orders.OrderBy(o => o.GetTotalCost(OrderItemRepo.GetOrderItems(o.Id).ToList(),
                                                            cupcakes.ToList()));
                break;

            case "order_total_desc":
                orders = orders.OrderByDescending(o => o.GetTotalCost(OrderItemRepo.GetOrderItems(o.Id).ToList(),
                                                                      cupcakes.ToList()));
                break;

            default:
                orders = orders.OrderBy(o => o.OrderTime);
                break;
            }

            var viewModels = orders.Select(o => new OrderViewModel
            {
                OrderId      = o.Id,
                LocationId   = o.OrderLocation,
                LocationName = locations.Single(l => l.Id == o.OrderLocation).Name,
                CustomerId   = o.OrderCustomer,
                CustomerName = customers.Single(c => c.Id == o.OrderCustomer).ReturnFullName(),
                OrderTime    = o.OrderTime,
                Locations    = locations.ToList(),
                Customers    = customers.ToList(),
                Cupcakes     = cupcakes.ToList(),
                OrderItems   = OrderItemRepo.GetOrderItems(o.Id).ToList(),
                OrderTotal   = OrderRepo.GetOrder(o.Id).GetTotalCost(OrderItemRepo.GetOrderItems(o.Id).ToList(),
                                                                     cupcakes.ToList())
            }).ToList();

            return(View(viewModels));
        }
Ejemplo n.º 10
0
        public ActionResult Inventory(int id)
        {
            P1B.Location currentLocation = LocRepo.GetLocationById(id);
            ViewData["currentLocation"] = currentLocation.Name;

            IEnumerable <P1B.LocationInventory> locInvs = LocationInventoryRepo.GetLocationInventoryByLocationId(id)
                                                          .OrderBy(li => li.IngredientId);
            List <P1B.Ingredient> ings = IngRepo.GetIngredients().ToList();

            var viewModels = locInvs.Select(li => new LocationInventoryViewModel
            {
                LocationId   = id,
                LocationName = currentLocation.Name,
                IngredientId = li.IngredientId,
                // https://stackoverflow.com/questions/272633/add-spaces-before-capital-letters
                IngredientType   = Regex.Replace(ings.Single(i => i.Id == li.IngredientId).Type, "([a-z])([A-Z])", "$1 $2"),
                IngredientUnits  = ings.Single(i => i.Id == li.IngredientId).Units,
                IngredientAmount = li.Amount
            }).ToList();

            return(View(viewModels));
        }
        /*public LocationController(ILocationRepo repo) =>
         *  Repo = repo ?? throw new ArgumentNullException(nameof(repo));*/

        // GET: Location
        public ActionResult Index()
        {
            IEnumerable <Library.Location> locationList = LocRepo.GetAllLocations().ToList();

            /*var viewModels = locationList.Select(s=>new LocationViewModel
             * {
             *  LocationId=s.LocationId,
             *  LocationName=s.Name
             * }
             *  ).ToList();*/
            IEnumerable <LocationViewModel> viewModels = locationList.Select(x => new LocationViewModel
            {
                LocationId   = x.LocationId,
                LocationName = x.Name,
                Address      = x.Address
            });

            /*var locationModels=locationList.Select(s=>new LocationViewModel
             * {
             *
             * }*/
            return(View(viewModels));
        }
        // GET: Location/Details/5
        public ActionResult Details(int id)
        {
            IEnumerable <Order> orders = LocRepo.GetOrderHistoryByLocation(id);
            var ViewModels             = orders.Select(o => new OrderViewModel
            {
                OrderId    = o.OrderId,
                OrderTime  = o.OrderTime,
                LocationId = o.LocationId,
                CustomerId = o.CustomerId,
                OrderTotal = o.OrderTotal
            });

            return(View(ViewModels));

            /*
             * IEnumerable<Library.Order> OrderList = LocRepo.GetOrderHistoryByLocation(1);
             * //maybe add location repo here
             * var viewModels = OrderList.Select(o => new OrderViewModel
             * {
             *  OrderId=o.OrderId,
             *
             * });*/
        }
Ejemplo n.º 13
0
        public ActionResult Create(Project1.ViewModels.LocationViewModel viewModel)
        {
            try
            {
                if (viewModel.LocationName.Length == 0)
                {
                    string message = "The location name cannot be empty.";
                    TempData["ErrorMessage"] = message;
                    _logger.LogWarning(message);
                    return(RedirectToAction("Error", "Home"));
                }
                if (LocRepo.CheckLocationNameExists(viewModel.LocationName))
                {
                    string message = "This location name has already been used in the database.";
                    TempData["ErrorMessage"] = message;
                    _logger.LogWarning(message);
                    return(RedirectToAction("Error", "Home"));
                }

                // TODO: Add insert logic here
                var newLocation = new P1B.Location
                {
                    Name = viewModel.LocationName
                };

                // TODO: Add insert logic here
                LocRepo.AddLocation(newLocation);
                int newLocationId = LocRepo.GetLastLocationAdded();
                LocationInventoryRepo.FillLocationInventory(newLocationId);
                return(RedirectToAction(nameof(Index)));
            }
            catch (Exception ex)
            {
                return(View());
            }
        }
Ejemplo n.º 14
0
        public IActionResult Index()
        {
            Project1.ViewModels.HomeViewModel viewModel = new ViewModels.HomeViewModel
            {
                Locations  = LocRepo.GetAllLocations().ToList(),
                Customers  = CustomerRepo.GetAllCustomers().ToList(),
                Cupcakes   = CupcakeRepo.GetAllCupcakes().ToList(),
                Orders     = OrderRepo.GetAllOrders().ToList(),
                OrderItems = OrderItemRepo.GetAllOrderItems().ToList()
            };
            decimal sum         = 0;
            decimal incrementer = 0;

            foreach (var order in viewModel.Orders)
            {
                sum += order.GetTotalCost(OrderItemRepo.GetOrderItems(order.Id).ToList(), viewModel.Cupcakes);
                incrementer++;
            }
            if (incrementer > 0)
            {
                viewModel.OrderTotalAverage = sum / incrementer;
            }

            if (viewModel.Locations.Count > 0)
            {
                viewModel.LocationMostOrders = viewModel.Locations.MaxBy(sL =>
                                                                         LocRepo.GetLocationOrderHistory(sL.Id).Count()).OrderBy(sL => sL.Id).First().Name;
                if (viewModel.Orders.Count > 0)
                {
                    viewModel.LocationWithLatestOrder = viewModel.Locations.Single(l => l.Id ==
                                                                                   viewModel.Orders.MaxBy(o => o.OrderTime).First().OrderLocation).Name;
                }
            }

            return(View(viewModel));
        }
Ejemplo n.º 15
0
        public ActionResult Create(Project1.ViewModels.OrderViewModel viewModel)
        {
            try
            {
                for (int i = 0; i < viewModel.OrderItems.Count; i++)
                {
                    viewModel.OrderItems[i].CupcakeId = i + 1;
                }
                List <Project1.BLL.OrderItem> newOrderItems = viewModel.OrderItems
                                                              .Where(oi => oi.Quantity != null).ToList();
                if (newOrderItems.Count == 0)
                {
                    string message = "The order must have at least one cupcake.";
                    TempData["ErrorMessage"] = message;
                    _logger.LogWarning(message);
                    return(RedirectToAction("Error", "Home"));
                }

                viewModel.Locations    = LocRepo.GetAllLocations().ToList();
                viewModel.Customers    = CustomerRepo.GetAllCustomers().ToList();
                viewModel.Cupcakes     = CupcakeRepo.GetAllCupcakes().ToList();
                viewModel.CustomerName = viewModel.Customers.Single(c => c.Id == viewModel.CustomerId).ReturnFullName();
                viewModel.LocationName = viewModel.Locations.Single(l => l.Id == viewModel.LocationId).Name;

                if (!CustomerRepo.CheckCustomerExists(viewModel.CustomerId))
                {
                    string message = $"Customer {viewModel.CustomerName} is not in the database.";
                    TempData["ErrorMessage"] = message;
                    _logger.LogWarning(message);
                    return(RedirectToAction("Error", "Home"));
                }
                if (!LocRepo.CheckLocationExists(viewModel.LocationId))
                {
                    string message = $"Location {viewModel.LocationName} is not in the list of stores.";
                    TempData["ErrorMessage"] = message;
                    _logger.LogWarning(message);
                    return(RedirectToAction("Error", "Home"));
                }
                // The following checks to see if the customer can order from this store location
                // If the customer has ordered at this store within the past 2 hours, than they shouldn't be
                // able to order again.
                var orders = OrderRepo.GetAllOrders().ToList();
                if (!Project1.BLL.Customer.CheckCustomerCanOrder(viewModel.CustomerId,
                                                                 viewModel.LocationId, orders))
                {
                    string message = "Customer can't place an order at this store because it hasn't been 2 hours \n" +
                                     "since there last order yet.";
                    TempData["ErrorMessage"] = message;
                    _logger.LogWarning(message);
                    return(RedirectToAction("Error", "Home"));
                }
                foreach (var cupcake in newOrderItems)
                {
                    if (!CupcakeRepo.CheckCupcakeExists(cupcake.CupcakeId))
                    {
                        string message = $"Cupcake {viewModel.Cupcakes.Single(c => c.Id == cupcake.CupcakeId).Type} " +
                                         $"is not in the database";
                        TempData["ErrorMessage"] = message;
                        _logger.LogWarning(message);
                        return(RedirectToAction("Error", "Home"));
                    }
                    int qnty = cupcake.Quantity ?? 0;
                    if (!Project1.BLL.Order.CheckCupcakeQuantity(qnty))
                    {
                        string message = $"Quantity for cupcake " +
                                         $"{viewModel.Cupcakes.Single(c => c.Id == cupcake.CupcakeId).Type} " +
                                         $"is out of range";
                        TempData["ErrorMessage"] = message;
                        _logger.LogWarning(message);
                        return(RedirectToAction("Error", "Home"));
                    }
                }
                // The following gets all orders and their associated order items in order
                // to validate that the store location's supply of the cupcakes in the customer's
                // requested order have not been exhausted.
                // Cupcake exhaustion happens when a store location has had more than 1000 cupcakes of one
                // type sold within 24 hours, at that point they cannot sell anymore.
                // This is arbitrary business logic that I added in order to satisfy the Project0
                // requirements.
                var orderItems = OrderItemRepo.GetAllOrderItems().ToList();
                if (!Project1.BLL.Location.CheckCanOrderCupcake(viewModel.LocationId,
                                                                orders, orderItems, newOrderItems))
                {
                    string message = $"This store has exhausted supply of one of those cupcakes. " +
                                     $"Try back in 24 hours.";
                    TempData["ErrorMessage"] = message;
                    _logger.LogWarning(message);
                    return(RedirectToAction("Error", "Home"));
                }
                // The following gets the recipes for the cupcakes in the customer's requested order
                // and checks to make sure that the store location's inventory can support the order.
                var recipes     = RecipeItemRepo.GetRecipes(newOrderItems);
                var locationInv = LocationInventoryRepo.GetLocationInventoryByLocationId(viewModel.LocationId).ToList();
                if (!Project1.BLL.Location.CheckOrderFeasible(recipes, locationInv, newOrderItems))
                {
                    string message = $"This store does not have enough ingredients to place " +
                                     $"the requested order.";
                    TempData["ErrorMessage"] = message;
                    _logger.LogWarning(message);
                    return(RedirectToAction("Error", "Home"));
                }

                var newOrder = new P1B.Order
                {
                    OrderLocation = viewModel.LocationId,
                    OrderCustomer = viewModel.CustomerId,
                    OrderTime     = DateTime.Now
                };
                OrderRepo.AddCupcakeOrder(newOrder);

                int newOrderId = OrderRepo.GetLastCupcakeOrderAdded();
                for (int i = 0; i < newOrderItems.Count; i++)
                {
                    newOrderItems[i].OrderId = newOrderId;
                }

                OrderItemRepo.AddCupcakeOrderItems(newOrderItems);
                LocationInventoryRepo.UpdateLocationInv(viewModel.LocationId, recipes, newOrderItems);

                return(RedirectToAction(nameof(Index)));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.ToString());
                return(RedirectToAction("Error", "Home"));
            }
        }
        public ActionResult Create(Order webOrder, string Locations, string Pizza1, string Pizza2, string Pizza3, string Pizza4, string Pizza5,
                                   string Pizza6, string Pizza7, string Pizza8, string Pizza9, string Pizza10, string Pizza11, string Pizza12)
        {
            try
            {
                lib.User   CurrentUser = UserRepo.GetUserByUsername(webOrder.Username);
                lib.Orders order;
                if (ModelState.IsValid)
                {
                    string       loc      = Locations;
                    lib.Location location = LocRepo.GetLocationByCityname(loc);
                    if (loc.ToLower().Equals("reston") || loc.ToLower().Equals("herndon") ||
                        loc.ToLower().Equals("hattontown") || loc.ToLower().Equals("dulles"))
                    {
                        if (Repo.GetOrdersByUser(webOrder.Username).LastOrDefault(o => o.StoreLocation.ToLower().Equals(loc.ToLower())) == null)
                        {
                            location.DecreaseInventory(int.Parse(Pizza1));
                            location.DecreaseInventory(int.Parse(Pizza2));
                            location.DecreaseInventory(int.Parse(Pizza3));
                            location.DecreaseInventory(int.Parse(Pizza4));
                            location.DecreaseInventory(int.Parse(Pizza5));
                            location.DecreaseInventory(int.Parse(Pizza6));
                            location.DecreaseInventory(int.Parse(Pizza7));
                            location.DecreaseInventory(int.Parse(Pizza8));
                            location.DecreaseInventory(int.Parse(Pizza9));
                            location.DecreaseInventory(int.Parse(Pizza10));
                            location.DecreaseInventory(int.Parse(Pizza11));
                            location.DecreaseInventory(int.Parse(Pizza12));

                            decimal total = (Repo.GetPriceOfPizzaFromId(int.Parse(Pizza1))
                                             + (Repo.GetPriceOfPizzaFromId(int.Parse(Pizza2)))
                                             + (Repo.GetPriceOfPizzaFromId(int.Parse(Pizza3)))
                                             + (Repo.GetPriceOfPizzaFromId(int.Parse(Pizza4)))
                                             + (Repo.GetPriceOfPizzaFromId(int.Parse(Pizza5)))
                                             + (Repo.GetPriceOfPizzaFromId(int.Parse(Pizza6)))
                                             + (Repo.GetPriceOfPizzaFromId(int.Parse(Pizza7)))
                                             + (Repo.GetPriceOfPizzaFromId(int.Parse(Pizza8)))
                                             + (Repo.GetPriceOfPizzaFromId(int.Parse(Pizza9)))
                                             + (Repo.GetPriceOfPizzaFromId(int.Parse(Pizza10)))
                                             + (Repo.GetPriceOfPizzaFromId(int.Parse(Pizza11)))
                                             + (Repo.GetPriceOfPizzaFromId(int.Parse(Pizza12))));
                            if (total < 500)
                            {
                                int TotalPizzas = 1;
                                if (int.Parse(Pizza2) > 1)
                                {
                                    TotalPizzas++;
                                }
                                if (int.Parse(Pizza3) > 1)
                                {
                                    TotalPizzas++;
                                }
                                if (int.Parse(Pizza4) > 1)
                                {
                                    TotalPizzas++;
                                }
                                if (int.Parse(Pizza5) > 1)
                                {
                                    TotalPizzas++;
                                }
                                if (int.Parse(Pizza6) > 1)
                                {
                                    TotalPizzas++;
                                }
                                if (int.Parse(Pizza7) > 1)
                                {
                                    TotalPizzas++;
                                }
                                if (int.Parse(Pizza8) > 1)
                                {
                                    TotalPizzas++;
                                }
                                if (int.Parse(Pizza9) > 1)
                                {
                                    TotalPizzas++;
                                }
                                if (int.Parse(Pizza10) > 1)
                                {
                                    TotalPizzas++;
                                }
                                if (int.Parse(Pizza11) > 1)
                                {
                                    TotalPizzas++;
                                }
                                if (int.Parse(Pizza12) > 1)
                                {
                                    TotalPizzas++;
                                }
                                order = new lib.Orders
                                {
                                    NumPizzas     = TotalPizzas,
                                    OrderTime     = DateTime.Now,
                                    Username      = webOrder.Username,
                                    FirstName     = webOrder.FirstName,
                                    PizzaNum1     = int.Parse(Pizza1),
                                    PizzaNum2     = int.Parse(Pizza2),
                                    PizzaNum3     = int.Parse(Pizza3),
                                    PizzaNum4     = int.Parse(Pizza4),
                                    PizzaNum5     = int.Parse(Pizza5),
                                    PizzaNum6     = int.Parse(Pizza6),
                                    PizzaNum7     = int.Parse(Pizza7),
                                    PizzaNum8     = int.Parse(Pizza8),
                                    PizzaNum9     = int.Parse(Pizza9),
                                    PizzaNum10    = int.Parse(Pizza10),
                                    PizzaNum11    = int.Parse(Pizza11),
                                    PizzaNum12    = int.Parse(Pizza12),
                                    TotalCost     = total,
                                    StoreLocation = loc
                                };
                                CurrentUser.UserFavoritePizza(order);
                                UserRepo.UpdateUser(lib.Mapper.Map(CurrentUser));

                                LocRepo.EditLocation(lib.Mapper.Map(location));

                                Repo.AddOrder(order);
                                TempData["SuccessMessage"] = "Order successfully placed!";
                                return(RedirectToAction("Index", "User"));
                            }
                            else
                            {
                                TempData["ErrorMessage"] = "Error: Cost is over the $500 limit. Please adjust order to meet limit.";
                                return(RedirectToAction("Index", "User"));
                            }
                        }
                        else
                        {
                            lib.Order OrderToCheck = lib.Mapper.Map(Repo.GetOrdersByUser(webOrder.Username).LastOrDefault(o => o.StoreLocation.ToLower().Equals(loc.ToLower())));
                            DateTime  CurrentTime  = DateTime.Now;
                            if ((CurrentTime - OrderToCheck.OrderPlaced) >= TimeSpan.FromHours(2))
                            {
                                location.DecreaseInventory(int.Parse(Pizza1));
                                location.DecreaseInventory(int.Parse(Pizza2));
                                location.DecreaseInventory(int.Parse(Pizza3));
                                location.DecreaseInventory(int.Parse(Pizza4));
                                location.DecreaseInventory(int.Parse(Pizza5));
                                location.DecreaseInventory(int.Parse(Pizza6));
                                location.DecreaseInventory(int.Parse(Pizza7));
                                location.DecreaseInventory(int.Parse(Pizza8));
                                location.DecreaseInventory(int.Parse(Pizza9));
                                location.DecreaseInventory(int.Parse(Pizza10));
                                location.DecreaseInventory(int.Parse(Pizza11));
                                location.DecreaseInventory(int.Parse(Pizza12));

                                decimal total = (Repo.GetPriceOfPizzaFromId(int.Parse(Pizza1))
                                                 + (Repo.GetPriceOfPizzaFromId(int.Parse(Pizza2)))
                                                 + (Repo.GetPriceOfPizzaFromId(int.Parse(Pizza3)))
                                                 + (Repo.GetPriceOfPizzaFromId(int.Parse(Pizza4)))
                                                 + (Repo.GetPriceOfPizzaFromId(int.Parse(Pizza5)))
                                                 + (Repo.GetPriceOfPizzaFromId(int.Parse(Pizza6)))
                                                 + (Repo.GetPriceOfPizzaFromId(int.Parse(Pizza7)))
                                                 + (Repo.GetPriceOfPizzaFromId(int.Parse(Pizza8)))
                                                 + (Repo.GetPriceOfPizzaFromId(int.Parse(Pizza9)))
                                                 + (Repo.GetPriceOfPizzaFromId(int.Parse(Pizza10)))
                                                 + (Repo.GetPriceOfPizzaFromId(int.Parse(Pizza11)))
                                                 + (Repo.GetPriceOfPizzaFromId(int.Parse(Pizza12))));
                                if (total < 500)
                                {
                                    int TotalPizzas = 1;
                                    if (int.Parse(Pizza2) > 1)
                                    {
                                        TotalPizzas++;
                                    }
                                    if (int.Parse(Pizza3) > 1)
                                    {
                                        TotalPizzas++;
                                    }
                                    if (int.Parse(Pizza4) > 1)
                                    {
                                        TotalPizzas++;
                                    }
                                    if (int.Parse(Pizza5) > 1)
                                    {
                                        TotalPizzas++;
                                    }
                                    if (int.Parse(Pizza6) > 1)
                                    {
                                        TotalPizzas++;
                                    }
                                    if (int.Parse(Pizza7) > 1)
                                    {
                                        TotalPizzas++;
                                    }
                                    if (int.Parse(Pizza8) > 1)
                                    {
                                        TotalPizzas++;
                                    }
                                    if (int.Parse(Pizza9) > 1)
                                    {
                                        TotalPizzas++;
                                    }
                                    if (int.Parse(Pizza10) > 1)
                                    {
                                        TotalPizzas++;
                                    }
                                    if (int.Parse(Pizza11) > 1)
                                    {
                                        TotalPizzas++;
                                    }
                                    if (int.Parse(Pizza12) > 1)
                                    {
                                        TotalPizzas++;
                                    }
                                    order = new lib.Orders
                                    {
                                        NumPizzas     = TotalPizzas,
                                        OrderTime     = DateTime.Now,
                                        Username      = webOrder.Username,
                                        FirstName     = webOrder.FirstName,
                                        PizzaNum1     = int.Parse(Pizza1),
                                        PizzaNum2     = int.Parse(Pizza2),
                                        PizzaNum3     = int.Parse(Pizza3),
                                        PizzaNum4     = int.Parse(Pizza4),
                                        PizzaNum5     = int.Parse(Pizza5),
                                        PizzaNum6     = int.Parse(Pizza6),
                                        PizzaNum7     = int.Parse(Pizza7),
                                        PizzaNum8     = int.Parse(Pizza8),
                                        PizzaNum9     = int.Parse(Pizza9),
                                        PizzaNum10    = int.Parse(Pizza10),
                                        PizzaNum11    = int.Parse(Pizza11),
                                        PizzaNum12    = int.Parse(Pizza12),
                                        TotalCost     = total,
                                        StoreLocation = loc
                                    };
                                    CurrentUser.UserFavoritePizza(order);
                                    UserRepo.UpdateUser(lib.Mapper.Map(CurrentUser));

                                    LocRepo.EditLocation(lib.Mapper.Map(location));

                                    Repo.AddOrder(order);
                                    TempData["SuccessMessage"] = "Order successfully placed!";
                                    return(RedirectToAction("Index", "User"));
                                }
                                else
                                {
                                    TempData["ErrorMessage"] = "Error: Cost is over the $500 limit. Please adjust order to meet limit.";
                                    return(RedirectToAction("Index", "User"));
                                }
                            }
                            else
                            {
                                TempData["ErrorMessage"] = "Error: You have ordered from " + location.Name + " less than 2 hours ago." +
                                                           "Either select a new location or wait 2 hours.";
                                return(RedirectToAction("Index", "User"));
                            }
                        }
                    }
                    TempData["ErrorMessage"] = "Please select a valid location: Reston, Herndon, Hattontown, or Dulles.";
                    return(RedirectToAction("Index", "User"));
                }
                return(RedirectToAction(nameof(Index)));
            }
            catch (Exception ex)
            {
                return(View());
            }
        }
Ejemplo n.º 17
0
        // GET: Location
        public ActionResult Index()
        {
            IEnumerable <P1B.Location> locations = LocRepo.GetAllLocations();

            return(View(locations));
        }