Beispiel #1
0
        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);
        }