예제 #1
0
        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);
        }
예제 #2
0
        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);
        }