public ActionResult UpdatePizzaInOrder(long ID) { ActionResult response = null; try { PizzaDO pizzaDOtoUpdate = _pizzaDAO.ViewPizzaByID(ID); if (pizzaDOtoUpdate != null) { // This pizza exists in the database. OrderDO pizzaOrderDO = _orderDAO.GetOrderByID((long)pizzaDOtoUpdate.OrderID); if (pizzaOrderDO.UserID == GetSessionUserID() || GetSessionRole() == 1) { // The user is associated with this pizza OR the admin is trying to update the pizza. PizzaPO pizzaPOtoUpdate = Mapping.PizzaMapper.PizzaDOtoPizzaPO(pizzaDOtoUpdate); FillPizzaSelectItems(pizzaPOtoUpdate); response = View(pizzaPOtoUpdate); } else { // A regular user tried to update someone elses pizza. Logger.Log("WARNING", "PizzaController", "UpdatePizzaInOrder", "UserID: " + GetSessionUserID() + " tried to update someone else's pizza."); response = RedirectToAction("MyOrders", "Order"); } } else { // Pizza doesn't exist. if (GetSessionRole() == 1) // If the admin is using { TempData["ErrorMessage"] = "That doesn't exist."; RedirectToAction("ViewPendingOrders", "Order"); } else { response = RedirectToAction("MyOrders", "Order"); } } } catch (Exception exception) { Logger.LogExceptionNoRepeats(exception); } finally { if (response == null) { response = RedirectToAction("Index", "Home"); } } return(response); }
/// <summary> /// Creates a new PizzaPO with the SelectListItems properties filled. /// </summary> /// <returns>A new PizzaPO with the SelectListItems filled.</returns> private PizzaPO PizzaWithSelectItemsFilled() { PizzaPO pizzaPO = new PizzaPO(); FillPizzaSelectItems(pizzaPO); return(pizzaPO); }
public ActionResult UpdatePizzaInCart(PizzaPO form) { ActionResult response = null; if (ModelState.IsValid) { try { // If the CartIndex wasn't assigned in the GET UpdatePizzaInCart then // the user probably tried POSTing from AJAX or something. if (Session["CartIndex"] == null) { TempData["ErrorMessage"] = "An a problem occured will updating your pizza, try again."; response = RedirectToAction("Index", "Cart"); } else { int index = (int)Session["CartIndex"]; // Get the index that was stored in Session. Session.Remove("CartIndex"); // Remove the "CartIndex" key from the Session. SetSafePizzaValues(form); // Send the pizza to the business layer for the price calculation. form.Price = _pizzaBLO.GetPizzaCost(Mapping.PizzaMapper.PizzaPOtoPizzaBO(form)); List <PizzaPO> cart = (Session["Cart"] as List <PizzaPO>); // The user could've deleted a pizza from the cart before updating, so check if the index // is in the bounds of the cart. if (index < 0 || index >= cart.Count) { TempData["ErrorMessage"] = "Something happened while updating the pizza, please try again"; } else { TempData["SuccessMessage"] = "Updated the pizza"; cart[index] = form; } response = RedirectToAction("Index", "Cart"); } } catch (Exception exception) { Logger.LogExceptionNoRepeats(exception); } finally { if (response == null) { response = RedirectToAction("Index", "Home"); } } } return(response); }
/// <summary> /// A convenient way to set safe values on a pizza form. /// </summary> /// <param name="pizzaPO">The refrence to the PizzaPO you wish to set the safe values on.</param> /// <param name="resetDescription">Determines whether or not to reset the pizza's description.</param> private void SetSafePizzaValues(PizzaPO pizzaPO, bool resetDescription = true) { pizzaPO.ImagePath = null; if (resetDescription) { pizzaPO.Description = null; } // The OrderID will be set later when the user creates an order. pizzaPO.OrderID = null; }
public ActionResult UpdatePrefabPizza(PizzaPO form) { ActionResult response = null; try { PizzaDO pizzaDO = _pizzaDAO.ViewPizzaByID(form.PizzaID); if (pizzaDO != null) // If that pizza exists { PizzaPO pizzaPO = Mapping.PizzaMapper.PizzaDOtoPizzaPO(pizzaDO); if (pizzaPO.OrderID == null) // If this pizza is a prefab pizza. { string imagesPath = "/Content/Images/"; // Path to the images folder. form.Price = form.Price < 4.99M ? 4.99M : form.Price; // If the price is less than 4.99 set the price to 4.99. // If the images path doesn't exist then set the form image to the NoImageAvailable picture. if (!System.IO.File.Exists(Server.MapPath("~/") + form.ImagePath)) { form.ImagePath = imagesPath + "NoImageAvailable.png"; } _pizzaDAO.UpdatePizza(Mapping.PizzaMapper.PizzaPOtoPizzaDO(form)); TempData["SuccessMessage"] = "Pizza was successfully updated."; } } else // The pizza doesn't exist. { TempData["ErrorMessage"] = "That pizza doens't exist."; } response = RedirectToAction("PrefabPizzas", "Pizza"); } catch (Exception exception) { Logger.LogExceptionNoRepeats(exception); } finally { if (response == null) { response = RedirectToAction("Index", "Home"); } } return(response); }
public ActionResult CreatePrefabPizza(PizzaPO form) { ActionResult response = null; if (ModelState.IsValid) { try { string imagesPath = "/Content/Images/"; // Path to the images folder. form.Price = form.Price < 4.99M ? 4.99M : form.Price; // If the price is less than 4.99 set the price to 4.99. // If the images path doesn't exist then set the form image to the NoImageAvailable picture. if (!System.IO.File.Exists(Server.MapPath("~/") + form.ImagePath)) { form.ImagePath = imagesPath + "NoImageAvailable.png"; } // Add the new pizza to the database. _pizzaDAO.AddNewPrefabPizza(Mapping.PizzaMapper.PizzaPOtoPizzaDO(form)); TempData["SuccessMessage"] = "The pizza prefab was succesffully added."; response = RedirectToAction("PrefabPizzas", "Pizza"); } catch (Exception exception) { Logger.LogExceptionNoRepeats(exception); } finally { if (response == null) { TempData["ErrorMessage"] = "An problem occured while creating the prefab. Please try again"; FillPizzaSelectItems(form); response = View(form); } else { } } } else // The form was not valid. { FillPizzaSelectItems(form); response = View(form); } return(response); }
public static PizzaBO PizzaPOtoPizzaBO(PizzaPO from) { PizzaBO to = new PizzaBO(); to.PizzaID = from.PizzaID; to.OrderID = from.OrderID; to.Cheese = from.Cheese; to.Crust = from.Crust; to.ImagePath = from.ImagePath; to.Price = from.Price; to.Sauce = from.Sauce; to.Size = from.Size; to.Toppings = from.Toppings; to.Description = from.Description; return(to); }
public ActionResult UpdatePrefabPizza(long ID) { ActionResult response = null; try { PizzaDO pizzaDO = _pizzaDAO.ViewPizzaByID(ID); // Get the pizza by the ID. if (pizzaDO != null) // If a pizza by that Id exists. { PizzaPO pizzaPO = Mapping.PizzaMapper.PizzaDOtoPizzaPO(pizzaDO); FillPizzaSelectItems(pizzaPO); if (pizzaPO.OrderID == null) // If the pizza is a prefab pizza. { pizzaPO.Description = null; response = View(pizzaPO); } else // It's not a prefab pizza. { TempData["ErrorMessage"] = "That pizza was not a prefab please choose another pizza."; response = RedirectToAction("PrefabPizzas", "Pizza"); } } else // That pizza doesn't exist. { RedirectingPage("The product with ID " + ID + " doesn't exist.", ""); } } catch (Exception exception) { Logger.LogExceptionNoRepeats(exception); } finally { if (response == null) { response = RedirectToAction("Index", "Home"); } } return(response); }
public ActionResult UpdatePizzaInCart(PizzaPO form) { ActionResult response = null; try { if (ModelState.IsValid) { if (Session["CartIndex"] == null) { TempData["ErrorMessage"] = "An a problem occured will updating your pizza, try again."; response = RedirectToAction("Index", "Cart"); } else { int index = (int)Session["CartIndex"]; Session.Remove("CartIndex"); SetSafePizzaValues(form); // Send the pizza to the business layer for the price calculation. form.Price = _pizzaBLO.GetPizzaCost(Mapping.PizzaMapper.PizzaPOtoPizzaBO(form)); (Session["Cart"] as List <PizzaPO>)[index] = form; response = RedirectToAction("Index", "Cart"); } } } catch (Exception exception) { Logger.LogExceptionNoRepeats(exception); } finally { if (response == null) { response = RedirectToAction("Index", "Home"); } } return(response); }
public ActionResult UpdatePrefabPizza(long ID) { ActionResult response = null; try { PizzaDO pizzaDO = _pizzaDAO.ViewPizzaByID(ID); if (pizzaDO != null) // If a pizza by that Id exists. { PizzaPO pizzaPO = Mapping.PizzaMapper.PizzaDOtoPizzaPO(pizzaDO); FillPizzaSelectItems(pizzaPO); if (pizzaPO.OrderID == null) { pizzaPO.Description = null; response = View(pizzaPO); } else // It's not a prefab pizza. { // TODO: Show admin the messup. Also log this. } } else { RedirectingPage("The product with ID " + ID + " doesn't exist.", ""); } } catch (Exception exception) { Logger.LogExceptionNoRepeats(exception); } finally { if (response == null) { response = RedirectToAction("Index", "Home"); } } return(response); }
public ActionResult DeletePrefabPizza(long ID) { ActionResult response = null; try { PizzaDO pizzaDO = _pizzaDAO.ViewPizzaByID(ID); if (pizzaDO != null) // If that pizza exists { PizzaPO existingPizza = Mapping.PizzaMapper.PizzaDOtoPizzaPO(pizzaDO); if (existingPizza.OrderID == null) // If the pizza is in fact a prefab { _pizzaDAO.DeletePizza(ID); TempData["SuccessMessage"] = "Pizza was successfully deleted"; response = RedirectToAction("PrefabPizzas", "Pizza"); } else // Otherwise, the pizza the Admin is trying to delete is not a prefab pizza. { response = RedirectingPage("That pizza is not a prefab.", "../PrefabPizzas"); } } else // Otherwise, the pizza didn't exist. { response = RedirectToAction("That pizza doesn't exist.", "../PrefabPizzas"); } } catch (Exception exception) { Logger.LogExceptionNoRepeats(exception); } finally { if (response == null) { response = RedirectToAction("Index", "Home"); } } return(response); }
/************** HELPER METHODS START **************/ /// <summary> /// Fills all of the SelectListItems in a refrence to a PizzaPO. /// </summary> /// <param name="pizzaPO">PizzaPO to fill the SelectListItems on.</param> private void FillPizzaSelectItems(PizzaPO pizzaPO) { pizzaPO.CrustSelectListItems = new List <SelectListItem>(); pizzaPO.CrustSelectListItems.Add(new SelectListItem { Text = "Select a Crust Type", Value = null, Disabled = true }); foreach (KeyValuePair <string, string> crustPairs in PizzaOptionsFactory.GetCrustDictionary()) { pizzaPO.CrustSelectListItems.Add(new SelectListItem { Text = crustPairs.Key, Value = crustPairs.Value }); } pizzaPO.SizeSelectListItems = new List <SelectListItem>(); foreach (KeyValuePair <string, string> sizePairs in PizzaOptionsFactory.GetSizeDictionary()) { pizzaPO.SizeSelectListItems.Add(new SelectListItem { Text = sizePairs.Key, Value = sizePairs.Value }); } pizzaPO.ToppingsSelectListItems = new List <SelectListItem>(); pizzaPO.ToppingsSelectListItems.Add(new SelectListItem { Text = "Select Toppings", Disabled = true }); foreach (KeyValuePair <string, string> toppingPairs in PizzaOptionsFactory.GetToppingsDictionary()) { pizzaPO.ToppingsSelectListItems.Add(new SelectListItem { Text = toppingPairs.Key, Value = toppingPairs.Key }); } pizzaPO.SauceSelectListItems = new List <SelectListItem>(); foreach (KeyValuePair <string, string> saucePairs in PizzaOptionsFactory.GetSauceDictionary()) { pizzaPO.SauceSelectListItems.Add(new SelectListItem { Text = saucePairs.Key, Value = saucePairs.Value }); } }
public ActionResult CreatePizza(PizzaPO form) { ActionResult response = null; try { if (ModelState.IsValid) { SetSafePizzaValues(form); // Send the pizza to the business layer for price calculation. form.Price = _pizzaBLO.GetPizzaCost(Mapping.PizzaMapper.PizzaPOtoPizzaBO(form)); // Add the pizza to the cart. (Session["Cart"] as List <PizzaPO>).Add(form); response = RedirectToAction("Index", "Cart"); } else // The form wasn't valid. { TempData["ErrorMessage"] = "Please fix the problems shown below"; FillPizzaSelectItems(form); response = View(form); } } catch (Exception exception) { Logger.LogExceptionNoRepeats(exception); } finally { if (response == null) { response = RedirectToAction("Index", "Home"); } } return(response); }
public ActionResult CreatePrefabPizza(PizzaPO form) { ActionResult response = null; try { if (ModelState.IsValid) { string imagesPath = "/Content/Images/"; form.Price = form.Price < 4.99M ? 4.99M : form.Price; if (!System.IO.File.Exists(Server.MapPath("~/") + form.ImagePath)) { form.ImagePath = imagesPath + "NoImageAvailable.png"; } _pizzaDAO.AddNewPrefabPizza(Mapping.PizzaMapper.PizzaPOtoPizzaDO(form)); } else { FillPizzaSelectItems(form); response = View(form); } } catch (Exception exception) { Logger.LogExceptionNoRepeats(exception); } finally { if (response == null) { response = RedirectToAction("Index", "Home"); } } return(response); }
public ActionResult DeleteFromOrder(long ID) { ActionResult response = null; int rowsAffected = 0; try { // Get the pizza the user is currently trying to delete from the DB. PizzaDO pizzaDO = _pizzaDAO.ViewPizzaByID(ID); if (pizzaDO != null) // If the pizza exists in the DB { PizzaPO pizzaPO = Mapping.PizzaMapper.PizzaDOtoPizzaPO(pizzaDO); if (pizzaPO.OrderID == null) // If this pizza is a prefab pizza. { // Thats a prefab pizza and that shouldn't be deleted from this action. if (GetSessionRole() == 1) { TempData["ErrorMessage"] = "You must delete that pizza from this page."; response = RedirectToAction("PrefabPizzas", "Pizza"); } else { } } else // Otherwise, the pizza isn't a prefab. { // Get the order that this pizza is associated with the pizza. // Use this later to update the new total for the order. OrderPO orderPO = Mapping .OrderMapper .OrderDOtoOrderPO(_orderDAO.GetOrderByID((long)pizzaPO.OrderID)); if (GetSessionRole() == 1) // If current user is an Admin. { // Delete the pizza from the order. rowsAffected = _pizzaDAO.DeletePizza(ID); } else { // Check to make sure that the current user is associated with the pizza's order. if (GetSessionUserID() != orderPO.UserID) // If the order is not tied to the current user... { Logger.Log("WARNING", "PizzaController", "DeletePizza", "User #" + GetSessionUserID() + " tried to delete someone elses pizza"); response = RedirectingPage("You do not have enough permissions to change a customers order.", "../../"); } else // The user is trying to delete their own pizza. { if (orderPO.Paid) // If the order has already been paid for. { // Send the user back to the Order Details page. TempData["ErrorMessage"] = "The order cannot be changed since it has already been paid for."; response = RedirectToAction("OrderDetails", "Order", new { ID = orderPO.OrderID }); } else { // The order hasn't been paid for yet, so it's oaky to delete the pizza. rowsAffected = _pizzaDAO.DeletePizza(ID); response = RedirectToAction("OrderDetails", "Order", new { ID = orderPO.OrderID }); } } } if (rowsAffected > 0) // If a database call was made and it was successfull. { // Recalculate the total for the order. // Get all of the pizzas associated with this order List <PizzaBO> pizzaBOList = Mapping .PizzaMapper .PizzaDOListToPizzaBOList(_pizzaDAO.GetPizzasByOrderID(orderPO.OrderID)); if (pizzaBOList.Count == 0) // If there are no pizzas tied to this order... { // Delete the order. response = RedirectToAction("DeleteOrder", "Order", new { ID = orderPO.OrderID }); } else { // Calculate the new total decimal newTotal = _pizzaBLO.GetCostOfPizzas(pizzaBOList); // Update the order's total. _orderDAO.UpdateOrderTotal(orderPO.OrderID, newTotal); // Redirect the user to the order details page. TempData["SuccessMessage"] = "Successfully delete the pizza from the order."; response = RedirectToAction("OrderDetails", "Order", new { ID = orderPO.OrderID }); } } } } else { TempData["ErrorMessage"] = "That pizza doesn't exists."; } } catch (Exception exception) { Logger.LogExceptionNoRepeats(exception); } finally { if (response == null) { response = RedirectToAction("Index", "Home"); } } return(response); }
private void FillPizzaSelectItems(PizzaPO pizzaPO) { pizzaPO.CrustSelectListItems = new List <SelectListItem>(); pizzaPO.CrustSelectListItems.Add(new SelectListItem { Text = "Select a Crust Type", Value = null, Disabled = true }); pizzaPO.CrustSelectListItems.Add(new SelectListItem { Text = "Hand Tossed", Value = "Hand Tossed" }); pizzaPO.SizeSelectListItems = new List <SelectListItem>(); pizzaPO.SizeSelectListItems.Add(new SelectListItem { Text = "Small 6 in.", Value = "6" }); pizzaPO.SizeSelectListItems.Add(new SelectListItem { Text = "Medium 8 in.", Value = "8" }); pizzaPO.ToppingsSelectListItems = new List <SelectListItem>(); pizzaPO.ToppingsSelectListItems.Add(new SelectListItem { Text = "Select Toppings", Disabled = true }); pizzaPO.ToppingsSelectListItems.Add(new SelectListItem { Text = "Pepperoni", Value = "Pepperoni" }); pizzaPO.ToppingsSelectListItems.Add(new SelectListItem { Text = "Sausage", Value = "Sausage" }); pizzaPO.ToppingsSelectListItems.Add(new SelectListItem { Text = "Bacon", Value = "Bacon" }); pizzaPO.ToppingsSelectListItems.Add(new SelectListItem { Text = "Mushroom", Value = "Mushroom" }); pizzaPO.ToppingsSelectListItems.Add(new SelectListItem { Text = "Onion", Value = "Onion" }); pizzaPO.ToppingsSelectListItems.Add(new SelectListItem { Text = "Pineapple", Value = "Pineapple" }); pizzaPO.ToppingsSelectListItems.Add(new SelectListItem { Text = "Spinach", Value = "Spinach" }); pizzaPO.ToppingsSelectListItems.Add(new SelectListItem { Text = "Jalapeno", Value = "Jalapeno" }); pizzaPO.ToppingsSelectListItems.Add(new SelectListItem { Text = "Tomato", Value = "Tomato" }); pizzaPO.SauceSelectListItems = new List <SelectListItem>(); pizzaPO.SauceSelectListItems.Add(new SelectListItem { Text = "Tomato Sauce", Value = "Tomato" }); pizzaPO.SauceSelectListItems.Add(new SelectListItem { Text = "Barbecue sauce", Value = "Barbecue" }); pizzaPO.SauceSelectListItems.Add(new SelectListItem { Text = "Hummus", Value = "Hummus" }); }
public ActionResult DeleteFromOrder(long ID) { ActionResult response = null; int rowsAffected = 0; try { PizzaDO pizzaDO = _pizzaDAO.ViewPizzaByID(ID); if (pizzaDO != null) { PizzaPO pizzaPO = Mapping.PizzaMapper.PizzaDOtoPizzaPO(pizzaDO); if (pizzaPO.OrderID == null) { // Thats a prefab pizza and that shouldn't be deleted from this action. if (GetSessionRole() == 1) { TempData["ErrorMessage"] = "You must delete that pizza from this page."; response = RedirectToAction("PrefabPizzas", "Pizza"); } } else { // Get the order that this pizza is associated with the pizza. // Use this later to update the new total for the order. OrderPO orderPO = Mapping .OrderMapper .OrderDOtoOrderPO(_orderDAO.GetOrderByID((long)pizzaPO.OrderID)); if (GetSessionRole() == 1) { rowsAffected = _pizzaDAO.DeletePizza(ID); } else { // Check to make sure that the current user is associated with the pizza's order. if (GetSessionUserID() == orderPO.UserID) { // The user is deleting their own pizza, so that's okay. rowsAffected = _pizzaDAO.DeletePizza(ID); response = RedirectToAction("OrderDetails", "Order", new { ID = orderPO.OrderID }); } else { Logger.Log("WARNING", "PizzaController", "DeletePizza", "User #" + GetSessionUserID() + " tried to delete someone elses pizza"); response = RedirectingPage("You do not have enough permissions to change a customers order.", "../../"); } } if (rowsAffected > 0) { // Recalculate the total for the order. // Get all of the pizza associated with this order List <PizzaBO> pizzaBOList = Mapping .PizzaMapper .PizzaDOListToPizzaBOList(_pizzaDAO.GetPizzasByOrderID(orderPO.OrderID)); // Calculate the new total decimal newTotal = _pizzaBLO.GetCostOfPizzas(pizzaBOList); // Update the order's total. _orderDAO.UpdateOrderTotal(orderPO.OrderID, newTotal); } } } else { TempData["ErrorMessage"] = "That pizza doesn't exists."; } } catch (Exception exception) { Logger.LogExceptionNoRepeats(exception); } finally { if (response == null) { response = RedirectToAction("Index", "Home"); } } return(response); }
public ActionResult UpdatePizzaInOrder(long ID) { ActionResult response = null; try { PizzaDO pizzaDOtoUpdate = _pizzaDAO.ViewPizzaByID(ID); if (pizzaDOtoUpdate != null) { // This pizza exists in the database. // Get the order that the pizza is associated with. OrderPO pizzaOrderPO = Mapping .OrderMapper .OrderDOtoOrderPO( _orderDAO.GetOrderByID((long)pizzaDOtoUpdate.OrderID) ); // If the current user is tied to the Pizza's order OR if the current user is an Admin. if (pizzaOrderPO.UserID == GetSessionUserID() || GetSessionRole() == 1) { // Map the pizza the user is trying to update to a PizzaPO PizzaPO pizzaPOtoUpdate = Mapping.PizzaMapper.PizzaDOtoPizzaPO(pizzaDOtoUpdate); if (pizzaOrderPO.Paid) // If the order has already been paid for. { // Redirect the user to the order's details. TempData["ErrorMessage"] = "You cannot update a pizza on an order that has already been paid for."; response = RedirectToAction("OrderDetails", "Order", new { ID = pizzaOrderPO.OrderID }); } else // Otherwise, the pizza can be updated. { FillPizzaSelectItems(pizzaPOtoUpdate); // Pass the PizzaPO to the view. response = View(pizzaPOtoUpdate); } } else { // A regular user tried to update someone elses pizza. Logger.Log("WARNING", "PizzaController", "UpdatePizzaInOrder", "UserID: " + GetSessionUserID() + " tried to update someone else's pizza."); response = RedirectToAction("MyOrders", "Order"); } } else // The pizza doesn't exist. { if (GetSessionRole() == 1) // If the current user is an Admin { TempData["ErrorMessage"] = "That doesn't exist."; RedirectToAction("ViewPendingOrders", "Order"); } else { response = RedirectToAction("MyOrders", "Order"); } } } catch (Exception exception) { Logger.LogExceptionNoRepeats(exception); } finally { if (response == null) { response = RedirectToAction("Index", "Home"); } } return(response); }
public ActionResult CreatePrefabPizza() { PizzaPO pizzaPO = PizzaWithSelectItemsFilled(); return(View(pizzaPO)); }
public ActionResult UpdatePizzaInOrder(PizzaPO form) { // Give response a default value. ActionResult response = RedirectToAction("Index", "Home"); OrderDO pizzasOrder = _orderDAO.GetOrderByID((long)form.OrderID); if (pizzasOrder.Paid) // If the order has already been paid for. { TempData["ErrorMessage"] = "You cannot update a pizza on an order that has already been paid for."; response = RedirectToAction("OrderDetails", "Order", new { ID = pizzasOrder.OrderID }); } else if (ModelState.IsValid) { if (pizzasOrder != null) // If that order exists { // Check if the pizza form is associated with this user OR if the user is an admin if (pizzasOrder.UserID == GetSessionUserID() || GetSessionRole() == 1) { // Get the new price for the pizza. form.Price = _pizzaBLO.GetPizzaCost(Mapping.PizzaMapper.PizzaPOtoPizzaBO(form)); if (_pizzaDAO.UpdatePizza(Mapping.PizzaMapper.PizzaPOtoPizzaDO(form)) > 0) { // If the pizza was able to update then try to update the Order. // First get all the pizzas associated with this order. List <PizzaDO> pizzas = _pizzaDAO.GetPizzasByOrderID((long)form.OrderID); // Get the total cost for the pizzas that are linked to the orderID decimal newTotal = _pizzaBLO.GetCostOfPizzas(Mapping.PizzaMapper.PizzaDOListToPizzaBOList(pizzas)); // Update the orders total cost. if (_orderDAO.UpdateOrderTotal((long)form.OrderID, newTotal)) // If updated the price { response = RedirectToAction("OrderDetails", "Order", new { ID = form.OrderID }); } else // Otherwise the order is now out of sync { Logger.Log("WARNING", "PizzaController", "UpdatePizzaInOrder", "After trying to update a pizza in orderID: " + form.OrderID + " the total was not updated."); } } else // Otherwise the pizza couldn't update. { TempData["ErrorMessage"] = "Could not update the pizza, please try again later."; response = RedirectToAction("OrderDetails", "Order", new { ID = form.OrderID }); } } else // Otherwise the user shouldn't be trying to change this order. { Logger.Log("WARNING", "PizzaController", "UpdatePizzaInOrder", "UserID: " + GetSessionUserID() + " tried to update someone elses pizza."); } } else { // That pizza doesn't exist. TempData["ErrorMessage"] = "That pizza doesn't exist."; response = RedirectToAction("OrderDetails", "Order", new { ID = form.OrderID }); } } else { // The form is not valid. TempData["ErrorMessage"] = "Please fix the errors shown below."; FillPizzaSelectItems(form); response = View(form); } return(response); }