public async Task <IActionResult> Add(AddRecipeInputModel input) { if (!input.Image.FileName.EndsWith(".png")) { this.ModelState.AddModelError("Image", "Invalid file type."); } if (input.Image.Length > 10 * 1024 * 1024) { this.ModelState.AddModelError("Image", "File too big."); } if (!ModelState.IsValid) { return(this.View()); } // TODO: Save data using (FileStream fs = new FileStream( this.webHostEnvironment.WebRootPath + "/user.png", FileMode.Create)) { await input.Image.CopyToAsync(fs); } return(this.RedirectToAction(nameof(ThankYou))); }
public IActionResult AddUserAgent( [FromHeader(Name = "User-Agent")] string userAgent, AddRecipeInputModel recipeInputModel) { //we can ask different data from the httpRequest string cookie = this.HttpContext.Request.Cookies[".AspNet.Consent"]; return(this.Json(cookie)); }
public async Task <IActionResult> Add() { var model = new AddRecipeInputModel() { Categories = await this.categoriesService.GetAllAsSelectListItemAsync(), }; return(this.View(model)); }
public IActionResult Add(AddRecipeInputModel inputModel) { if (!ModelState.IsValid) { return(this.View()); } return(this.RedirectToAction("ThankYou")); }
public IActionResult Add() { var model = new AddRecipeInputModel { FirstCooked = DateTime.UtcNow, Time = new RecipeTimeInputModel() { CookingTime = 10, PreparationTime = 5 } }; return(this.View(model)); }
public async Task <IActionResult> Add(AddRecipeInputModel input) { if (!this.ModelState.IsValid) { input.Categories = await this.categoriesService.GetAllAsSelectListItemAsync(); return(this.View(input)); } await this.recipesService.AddAsync(input.Title, input.Content, input.Picture, input.Portions, input.PreparationTime, input.CookingTime, input.CategoryId); this.TempData["InfoMessage"] = GlobalConstants.SuccessAddedMessage; return(this.RedirectToAction(nameof(this.GetAll))); }
public IActionResult Add() { //creating default valus in the form for the user var model = new AddRecipeInputModel { Type = RecipeType.Unknown, FirstCooked = DateTime.UtcNow, Time = new RecipeTimeInputModel() { CookingTime = 10, PreparationTime = 5 }, }; return(this.View(model)); }
//[Bind("Ingredients, Name")] will bind only those 2 properties public IActionResult AddBind([Bind("Ingredients, Name")] AddRecipeInputModel recipeInputModel) { return(this.Json(recipeInputModel)); }
//[FromForm] attribute will be taken only from the form table in the view public IActionResult AddFromForm([FromForm] AddRecipeInputModel recipeInputModel) { return(this.Json(recipeInputModel)); }
public IActionResult Add(AddRecipeInputModel recipeInputModel) { return(this.Json(recipeInputModel)); }
public Task AddItemAsync(AddRecipeInputModel model) { throw new NotImplementedException(); }