예제 #1
0
        public ActionResult CreateRecipe()
        {
            String recipeName      = "";
            String longDescription = "";
            String shortDescription;
            String jsonIngredientList = null;

            HttpPostedFileBase image_file = Request.Files["image"];

            List <JsonIngredient> jsonIngredients = null;

            //if data is shit
            foreach (String key in Request.Form.AllKeys)
            {
                if (key == "name")
                {
                    recipeName = Request.Form[key];
                }
                if (key == "short_desc")
                {
                    shortDescription = Request.Form[key];
                }
                if (key == "long_desc")
                {
                    longDescription = Request.Form[key];
                }
                if (key == "ingredients")
                {
                    jsonIngredientList = Request.Form[key];
                    jsonIngredients    = new JavaScriptSerializer().Deserialize <List <JsonIngredient> >(jsonIngredientList);
                    ViewBag.test1      = jsonIngredientList + ":" + jsonIngredients;
                }
            }

            RecipeDAO.CreateRecipe(new FullRecipe(recipeName, longDescription, jsonIngredients));
            if (SaveImage(image_file, recipeName))
            {
                //save the file
                ViewBag.message = "the recipe have been saved";
                SaveImage(image_file, recipeName);
            }
            else
            {
                ViewBag.message = "the recipe was not saved";
            }


            return(View());
        }