コード例 #1
0
        public async Task <ActionResult <Response <RecipeResponse> > > AddRecipe([FromBody] RecipeRequest recipeRequest)
        {
            var token     = HttpContext.Request.Headers["Authorization"].FirstOrDefault();
            var userToken = token.Split(' ')[1];
            var user      = UserToken.FromToken(userToken);

            return(Ok(await _recipeService.AddRecipe(recipeRequest, user.UserId)));
        }
コード例 #2
0
        public async Task <ActionResult <Recipe> > CreateNewRecipe([FromBody] RecipePlusTags recipePlusTags)
        {
            Recipe recipe = recipePlusTags.recipe;
            //Recipe recipe = recipePlusTags.recipe;
            string   tags = recipePlusTags.tags;
            DateTime now  = DateTime.Now;

            recipe.DateCreated = now;
            List <RecipeTag> recipeTags = JsonConvert.DeserializeObject <List <RecipeTag> >(tags);


            /*string[] tags_arr = tags.Replace(" ", "").Split("#");
             *
             * foreach (string tag in tags_arr)
             * {​​​​
             * if (!String.IsNullOrEmpty(tag))
             * {​​​​
             * Tag t = new Tag
             * {​​​​
             * TagName = tag,
             * Warning = tag
             * }​​​​;
             *
             * RecipeTag recipeTag = new RecipeTag
             * {​​​​
             * Tag = t,
             * Recipe = recipe
             * }​​​​;
             * recipeTags.Add(recipeTag);
             * }​​​​
             * }​​​​*/


            recipe.RecipeTags = recipeTags;

            await _recipesService.AddRecipe(recipe);

            if (recipe == null)
            {
                return(NotFound());
            }


            return(recipe);
        }
コード例 #3
0
        public IActionResult ResetChecklist([FromBody] Recipe recipe)
        {
            if (!_recipeService.AddRecipe(recipe))
            {
                return(BadRequest());
            }

            return(Ok(recipe));
        }
コード例 #4
0
 public ActionResult <int> Post(RecipeAddDTO recipeData)
 {
     if (recipeData.Ingredients.Length == 0)
     {
         ModelState.AddModelError("Ingredients", "At least 1 ingredient is required.");
         return(new BadRequestObjectResult(ModelState));
     }
     return(this.HandleServiceResult(_recipeService.AddRecipe(recipeData)));
 }
コード例 #5
0
        public ActionResult <Recipe> AddRecipe([FromBody] RecipeAddModel recipe)
        {
            userInformation.ThrowErrorIfNotLoggedIn();

            return(Ok(service.AddRecipe(new Recipe
            {
                Name = recipe.Name,
                Ingredients = ConvertRequestItemList(recipe.Ingredients),
                Steps = recipe.Steps
            })));
        }
コード例 #6
0
 public IActionResult AddRecipe([FromBody] Recipe recipe)
 {
     if (_recipeService.AddRecipe(recipe))
     {
         return(CreatedAtRoute("GetRecipe", new { recipeId = recipe.Id }, recipe));
     }
     else
     {
         return(BadRequest());
     }
 }
コード例 #7
0
        public async Task <IActionResult> Create([FromBody] Recipe recipe, string gobackurl)
        {
            DateTime now = DateTime.Now;

            recipe.DateCreated = now;

            if (await _recipesService.AddRecipe(recipe))
            {
                return(Ok(new { id = recipe.RecipeId, gobackurl = gobackurl }));
            }

            ViewData["UserId"] = recipe.UserId;
            return(BadRequest());
        }
コード例 #8
0
ファイル: RecipeController.cs プロジェクト: GodEats/SEP3
        public async Task <ActionResult <Recipe> > AddRecipe([FromBody] Recipe recipe)
        {
            try
            {
                Recipe returned = await recipeService.AddRecipe(recipe);

                return(Ok(returned));
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return(StatusCode(500, e.Message));
            }
        }
コード例 #9
0
 public IActionResult AddRecipe([Bind("RecipeId,Name,Description,ImageUrl,CookingDecription,CookingTime,Category,RecipeType")] Recipe model)
 {
     try
     {
         if (ModelState.IsValid)
         {
             service.AddRecipe(model);
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
     return(RedirectToAction("Index"));
 }
コード例 #10
0
        public async Task <IActionResult> AddRecipe([FromForm] AddRecipeBindingModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelStateErrors()));
            }

            var userId = User.Identity.Name;
            var result = await _recipeService.AddRecipe(model, model.photo);

            if (result.ErrorOccured)
            {
                return(BadRequest(result));
            }

            return(Ok(result));
        }
コード例 #11
0
        public IActionResult Form(FormModel formModel)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction("Index"));
            }
            Recipe recipe = new Recipe();

            recipe.Name        = formModel.Name;
            recipe.Description = formModel.Description;
            recipe.Ingredients = new List <Ingredient>();
            recipe.AddIngredient(new Ingredient(formModel.ing1, formModel.qty1, formModel.meas1));
            recipe.AddIngredient(new Ingredient(formModel.ing2, formModel.qty2, formModel.meas2));

            _recipeService.AddRecipe(recipe);
            return(RedirectToAction(nameof(Index)));
        }
コード例 #12
0
        //[Route("post")]
        public async Task <ActionResult <Recipe> > CreateRecipe([FromBody] Recipe recipe)
        {
            try
            {
                recipe.User = _context.Users.FirstOrDefault();
                DateTime now = DateTime.Now;
                recipe.DateCreated = now;
                await _recipesService.AddRecipe(recipe);

                //_recipesService.AddRecipeNonAsync(recipe);

                return(recipe);
            } catch (Exception e)
            {
                Debug.WriteLine(e.Message);
                return(null);
            }
        }
コード例 #13
0
        public IActionResult AddNewRecipe([FromBody] RecipeModel recipe)
        {
            var newRecipe = new Recipes()
            {
                Name         = recipe.Name,
                Profile      = recipe.Profile,
                Picture      = recipe.Picture,
                Ingredients  = recipe.Ingredients,
                Instructions = recipe.Instructions
            };

            try
            {
                _recipeService.AddRecipe(newRecipe);
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
            return(Ok());
        }
コード例 #14
0
        private async Task NewRecipe()
        {
            ConsoleHelper.ColorWrite("What recipe would you like to add: ");
            var name = Console.ReadLine();

            RecipeDTO recipe = new RecipeDTO {
                Name = name
            };

            bool another = true;
            List <IngredientDTO> ingredients = new List <IngredientDTO>();

            while (another)
            {
                ConsoleHelper.ColorWrite("What ingredient would you like to add: ");
                var input = Console.ReadLine();

                try
                {
                    var ingredient = await _ingredientService.GetIngredientDTOByNameAsync(input);

                    var ingredientToAdd = new IngredientDTO {
                        Name = ingredient.Name
                    };
                    ingredients.Add(ingredientToAdd);
                }
                catch (KeyNotFoundException)
                {
                    ConsoleHelper.ColorWriteLine(ConsoleColor.DarkYellow, "The ingredient does not exist!");
                    ConsoleHelper.ColorWrite("Would you like to add it? (Y/n): ");
                    var add = Console.ReadLine();

                    if (Char.ToUpperInvariant(add[0]) == 'N')
                    {
                        ConsoleHelper.ColorWriteLine(ConsoleColor.Red, "Recipe not added.");
                        Console.WriteLine();
                        return;
                    }

                    ingredients.Add(new IngredientDTO {
                        Name = input
                    });
                }

                ConsoleHelper.ColorWrite("Would you like to add another ingredient? (y/N): ");
                var addAnother = Console.ReadLine();

                if (Char.ToUpperInvariant(addAnother[0]) != 'Y')
                {
                    another = false;
                }
            }

            try
            {
                await _recipeService.AddRecipe(recipe);

                ConsoleHelper.ColorWriteLine(ConsoleColor.Green, $"'{recipe.Name}' has been added.");
            }
            catch (KeyNotFoundException)
            {
                ConsoleHelper.ColorWriteLine(ConsoleColor.DarkYellow, $"{name} already exists.");
            }

            foreach (var ingredient in ingredients)
            {
                try
                {
                    await _recipeService.AddIngredientToRecipe(ingredient, recipe.Name);
                }
                catch (KeyNotFoundException)
                {
                    ConsoleHelper.ColorWriteLine($"'{recipe.Name}' does not exist.");
                }
            }

            Console.WriteLine();
            await this.Show();
        }
コード例 #15
0
 public async Task <IActionResult> CreateRecipe([FromBody] RecipeModel recipeModel)
 {
     return(await CreateResource(() => _recipeService.AddRecipe(recipeModel.Title, recipeModel.Description,
                                                                recipeModel.Steps, recipeModel.Notes, UserId), r => r.RecipeId));
 }
コード例 #16
0
        public async Task <RecipeModel> Add(RecipeFormModel recipeModel)
        {
            var recipe = await _recipeService.AddRecipe(recipeModel);

            return(new RecipeModel().Map(recipe));
        }
コード例 #17
0
 public ActionResult Create(RecipeDetails recipe)
 {
     recipe = _recipeService.AddRecipe(recipe);
     return(View("Edit", recipe));
 }
コード例 #18
0
        public async Task <IActionResult> SaveAsync([FromBody] RecipesDto recipeDto)
        {
            var result = await _recipeService.AddRecipe(recipeDto);

            return(Created("", result));
        }
コード例 #19
0
        public IActionResult AddRecipe([FromBody] RecipeViewModel recipe)
        {
            var response = _RecipeService.AddRecipe(recipe).Result;

            return(new OkObjectResult(response));
        }
コード例 #20
0
        public async Task <IActionResult> Post(Recipe recipe)
        {
            var newRecipe = await _recipes.AddRecipe(recipe);

            return(Ok(newRecipe));
        }
コード例 #21
0
        public async Task <IActionResult> Add(RecipeFormModel recipeModel)
        {
            var recipe = await _recipeService.AddRecipe(recipeModel);

            return(RedirectToRoute(new RouteValueDictionary(new { action = "GetRecipe", controller = "Recipe", recipeId = recipe.Id })));
        }
コード例 #22
0
        public ActionResult Create(RecipeViewModel obj)
        {
            int idUser         = int.Parse(Session["idUser"].ToString());
            var listCollection = _collectionService.GetAllCollections().Where(p => p.AccountId == idUser);//.ToSelectListItems(-1);

            obj.ListCollections = listCollection;

            if (obj.Name == null)
            {
                Session["error"] = "*You must input recipe name";
                return(View(obj));
            }
            else if (obj.idCollection <= 0 || obj.idCollection == null)
            {
                Session["error"] = "*You must select a collection.";
                return(View(obj));
            }
            else
            {
                var r = _recipeService.GetAllRecipes().Where(p => p.CollectionId == obj.idCollection && p.Name.ToLower().Equals(obj.Name.ToLower())).FirstOrDefault();
                if (r != null)
                {
                    Session["error"] = "*This recipe name already exists";
                    return(View(obj));
                }
            }


            Recipe rep = Mapper.Map <RecipeViewModel, Recipe>(obj);

            rep.CollectionId = obj.idCollection;
            rep.DateCreated  = rep.LastEdit = DateTime.Now;
            _recipeService.AddRecipe(rep);
            rep = _recipeService.GetAllRecipes().LastOrDefault();
            var id = rep.Id;

            //=============Upload===================
            if (obj.image != null)
            {
                HttpPostedFileBase file     = obj.image;                       // Get uploaded file
                string             fileName = Path.GetFileName(file.FileName); // Get file name
                string             dir      = "~/Images/Upload/Recipe" + id.ToString();
                String             phyDir   = Server.MapPath(dir);
                if (!Directory.Exists(phyDir))
                {
                    Directory.CreateDirectory(phyDir);
                }
                var path = Path.Combine(Server.MapPath(dir), fileName);
                file.SaveAs(path);

                rep.URL = "/Images/Upload/Recipe" + id.ToString() + "/" + fileName;
            }
            else
            {
                rep.URL = "/Content/Cookbook/images/no-image.jpg";
            }

            _recipeService.EditRecipe(rep);

            Session["error"] = null;

            return(Redirect("ViewDetail?id=" + id));
        }