コード例 #1
0
 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);
 }
コード例 #2
0
 public void DeleteRecipe(Recipe entity)
 {
     _context.Recipies.Remove(entity);
 }
コード例 #3
0
 public void CreateRecipe(Recipe entity)
 {
     _context.Recipies.Add(entity);
 }