public ActionResult OrderDetails(int orderId) { //get order details by id var LibOrder = Repo.GetOrderById(orderId); var WebOrder = MapperWeb.Map(LibOrder); string FirstName = Repo.FindFirstNameById(WebOrder.UserId); string LastName = Repo.FindLastNameById(WebOrder.UserId); WebOrder.Address = Repo.GetLocationNameById(WebOrder.LocationId); WebOrder.UserName = FirstName + " " + LastName; List <Library.Models.Pizza> pizzaList = Repo.FindPizzasInOrderPizzaByOrderID(WebOrder.OrderId); WebOrder.PizzaCountDetails = pizzaList.Count(); //fill out pizzadictionary List <bool> ToppingList = new List <bool>(); ToppingList.Add(false); ToppingList.Add(false); for (int i = 0; i < WebOrder.PizzaCountDetails; i++) { WebOrder.PizzaDictionary.Add(i, ToppingList); } for (int i = 0; i < WebOrder.PizzaCountDetails; i++) { List <bool> OrderToppingList = new List <bool>(); OrderToppingList.Add(pizzaList[i].Pepperoni); OrderToppingList.Add(pizzaList[i].ExtraCheese); WebOrder.PizzaDictionary[i] = OrderToppingList; } return(View(WebOrder)); }
public ActionResult NewUser(UserWeb user) { try { var libUser = MapperWeb.Map(user); var checkUser = Repo.FindUserId(libUser.FirstName, libUser.LastName); if (checkUser == 0) { Repo.AddUser(libUser); Repo.Save(); checkUser = Repo.FindUserId(libUser.FirstName, libUser.LastName); TempData["id"] = checkUser; TempData["FirstName"] = libUser.FirstName; TempData["MID"] = false; return(RedirectToAction("Index", "Home")); } else { ModelState.AddModelError(string.Empty, "User already exists."); return(View(user)); } // TODO: Add insert logic } catch { return(View(user)); } }
public ActionResult ExistingUser(UserWeb user) { try { var libUser = MapperWeb.Map(user); var checkUser = Repo.FindUserId(libUser.FirstName, libUser.LastName); if (checkUser > 0) { TempData["id"] = checkUser; TempData["FirstName"] = libUser.FirstName; TempData["MID"] = Repo.FindManagerFlagById(checkUser); return(RedirectToAction("Index", "Home")); } else { ModelState.AddModelError(string.Empty, "User doesn't exist. Please login as a new user or try again"); return(View(user)); } // TODO: Add insert logic } catch { return(View()); } }
public ActionResult SearchResultsLocation(int searchID, string searchOption) { try { var LocationHistory = (Repo.GetOrdersByLocationId(searchID)); if (searchOption == "1") //most expensive { LocationHistory.Sort((x, y) => y.OrderTotalValue.CompareTo(x.OrderTotalValue)); } else if (searchOption == "2") //least expensive { LocationHistory.Sort((x, y) => x.OrderTotalValue.CompareTo(y.OrderTotalValue)); } else if (searchOption == "3") //most recent { LocationHistory.Sort((x, y) => y.OrderTime.CompareTo(x.OrderTime)); } else //least recent { LocationHistory.Sort((x, y) => x.OrderTime.CompareTo(y.OrderTime)); } var WebLocationHistory = MapperWeb.Map(LocationHistory); foreach (var order in WebLocationHistory) { order.Address = Repo.GetLocationNameById(order.LocationId); } string FirstName = ""; string LastName = ""; foreach (var order in WebLocationHistory) { order.Address = Repo.GetLocationNameById(order.LocationId); FirstName = Repo.FindFirstNameById(order.UserId); LastName = Repo.FindLastNameById(order.UserId); order.UserName = FirstName + " " + LastName; } return(View(WebLocationHistory)); } catch { return(View()); } }
public ActionResult SearchResultsUser(int searchID, string searchOption) //functional { // try // { var UserHistory = (Repo.GetOrdersByUserId(searchID)); if (searchOption == "1") { UserHistory.Sort((x, y) => y.OrderTotalValue.CompareTo(x.OrderTotalValue)); } else if (searchOption == "2") { UserHistory.Sort((x, y) => x.OrderTotalValue.CompareTo(y.OrderTotalValue)); } else if (searchOption == "3") //most recent { UserHistory.Sort((x, y) => y.OrderTime.CompareTo(x.OrderTime)); } else //least recent { UserHistory.Sort((x, y) => x.OrderTime.CompareTo(y.OrderTime)); } var WebUserHistory = MapperWeb.Map(UserHistory); string FirstName = ""; string LastName = ""; foreach (var order in WebUserHistory) { order.Address = Repo.GetLocationNameById(order.LocationId); FirstName = Repo.FindFirstNameById(order.UserId); LastName = Repo.FindLastNameById(order.UserId); order.UserName = FirstName + " " + LastName; } return(View(WebUserHistory)); // } // catch // { // return View(); //} }
public ActionResult ByLocation(LocationWeb location) { try { var libLocaton = MapperWeb.Map(location); var checkLocation = Repo.GetLocationIdByName(location.Address); if (checkLocation > 0) { return(RedirectToAction("SearchResultsLocation", "OrderHistory", new { searchID = checkLocation, searchOption = location.SearchOption })); //add search option } else { ModelState.AddModelError(string.Empty, "Location doesn't exist. Please edit your search"); return(View()); } // TODO: Add insert logic } catch { return(View()); } }
public ActionResult ByUser(UserWeb user) { try { var libUser = MapperWeb.Map(user); var checkUser = Repo.FindUserId(libUser.FirstName, libUser.LastName); if (checkUser > 0) { return(RedirectToAction("SearchResultsUser", "OrderHistory", new { searchID = checkUser, searchOption = user.SearchOption })); //add search option } else { ModelState.AddModelError(string.Empty, "User doesn't exist. Please retype your search"); return(View(user)); } // TODO: Add insert logic } catch { return(View()); } }
public OrderHistoryController(Project1Repository repo, MapperWeb mapper) { Repo = repo; WebMap = mapper; }
public MovieController(IMovieService <MovieDto> movieService, MapperWeb mapper) { this.movieService = movieService; this.mapper = mapper; }
public ActionResult PlaceOrder(string[] ToppingListForm, OrderWeb order) { string numP = (string)TempData.Peek("numP"); string loc = (string)TempData.Peek("loc"); order.PizzaCountString = numP; //this is a string need to convert to int order.Address = loc; order.PizzaCountInt = Convert.ToInt32(numP); List <bool> ToppingList = new List <bool>(); for (int i = 0; i < order.NumOfToppings; i++) { ToppingList.Add(false); } for (int i = 0; i < order.PizzaCountInt; i++) { order.PizzaDictionary.Add(i, ToppingList); } int boolIndex = 0; for (int x = 0; x < order.PizzaCountInt; x++) { List <bool> OrderToppingList = new List <bool>(); for (int i = 0; i < order.NumOfToppings; i++) { if (ToppingListForm[boolIndex] == "true") { OrderToppingList.Add(true); boolIndex++; } else { OrderToppingList.Add(false); } boolIndex++; } order.PizzaDictionary[x] = OrderToppingList; } //inventory logic order.LocationId = Repo.GetLocationIdByName(order.Address); //get inventory from db by location id (for pizza and cheese) var PepperoniInventory = Repo.GetLocationPepperoniInventoryById(order.LocationId); var CheeseInventory = Repo.GetLocationCheeseInventoryById(order.LocationId); for (int x = 0; x < order.PizzaCountInt; x++) { order.PizzaIDs.Add(Repo.FindPizzaIdByToppings(order.PizzaDictionary[x])); } //subtract for each topping on each pizza for (int x = 0; x < order.PizzaCountInt; x++) //pepperoni first { if (order.PizzaDictionary[x][0]) { PepperoniInventory -= 1; } if (order.PizzaDictionary[x][1]) { CheeseInventory -= 1; } } //check if less than 0 if ((PepperoniInventory < 0) || (CheeseInventory < 0)) { ModelState.AddModelError("", "Sorry we do not have enough inventory at this location to create your order"); return(View(order)); } //if less than 0 add it back and return view //ModelState.AddModelError("", "Sorry we do not have enough inventory at this location to create your order"); //return View(order); order.OrderTime = DateTime.Now; order.UserId = (int)TempData.Peek("id"); decimal runningTotal = 0.00m; foreach (var id in order.PizzaIDs) { runningTotal += Repo.FindPriceByPizzaID(id); } order.TotalPrice = runningTotal; if ((Decimal.Compare(runningTotal, 500.00m)) > 0) //compare to $500 { ModelState.AddModelError("", "Sorry we cannot accept your order, it exceeds $500"); return(View(order)); } var libOrder = MapperWeb.Map(order); var location = new Library.Models.Location { LocationID = order.LocationId, Address = Repo.GetLocationNameById(order.LocationId), PepperoniInventory = PepperoniInventory, CheeseInventory = CheeseInventory }; Repo.UpdateLocationInventory(location); Repo.Save(); Repo.AddOrder(libOrder); Repo.Save(); order.OrderId = Repo.GetOrderIdByDateTime(order.OrderTime); foreach (var id in order.PizzaIDs) { Repo.AddOrderPizzas(order.OrderId, id); } Repo.Save(); return(RedirectToAction("OrderDetails", "Order", new { orderId = order.OrderId })); }
public CommentsController(ICommentsService commentsService, MapperWeb mapper) { this.commentsService = commentsService; this.mapper = mapper; }
public IActionResult SearchResults(string searchID) { var searchUser = MapperWeb.Map(Repo.SearchUserByFirstName(searchID)); return(View(searchUser)); }
public UserController(Project1Repository repo, MapperWeb mapper) { Repo = repo; Mapper = mapper; }