public IActionResult Create() { var model = new RecipeFormVM { Portions = 1 }; ViewBag.Categories = new SelectList(_categoryRepository.GetAllCategories(), "Id", "Name"); return View(model); }
public IActionResult Create(RecipeFormVM model) { if (ModelState.IsValid) { var entity = new Recipe { CategoryId = model.CategoryId, Title = model.Title, CoockTime = model.CoockTime, Content = model.Content, Portions = model.Portions }; entity.CreatedAt = DateTime.Now; _recipeRepository.CreateRecipe(entity); _recipeRepository.Commit(); //TempData["FlashMessage"] = "Рецепт создан"; //TempData["FlashType"] = FlashMessageType.Success; return RedirectToAction("Detail", new { id = entity.Id }); } ViewBag.Categories = new SelectList(_categoryRepository.GetAllCategories(), "Id", "Name"); return View(model); }