public IActionResult AddPhotoToRecipe(long RecipeId) { RecipePhotoModel model = new RecipePhotoModel(); model.RecipeId = RecipeId; return(View(model)); }
private string RecipeUploadedFile(RecipePhotoModel model) { if (model.ProfileImage == null) { throw new Exception(); } string uploadsFolder = Path.Combine(webHostEnvironment.WebRootPath, "images"); string uniqueFileName = model.ProfileImage.FileName; string filePath = Path.Combine(Path.Combine(webHostEnvironment.WebRootPath, "images"), model.ProfileImage.FileName); using (var fileStream = new FileStream(Path.Combine(Path.Combine(webHostEnvironment.WebRootPath, "images"), model.ProfileImage.FileName), FileMode.Create)) { model.ProfileImage.CopyTo(fileStream); } return(uniqueFileName); }
public IActionResult AddPhotoToRecipe(long RecipeId, RecipePhotoModel model) { if (ModelState.IsValid) { string uniqueFileName = RecipeUploadedFile(model); if (uniqueFileName == null) { throw new Exception(); } var recipe = recipeService.GetRecipeById(RecipeId); recipe.ImageUrl = uniqueFileName; recipeService.Update(recipe); } return(RedirectToAction("AddOwnRecipe", "User")); }