コード例 #1
0
 public IActionResult Dishprocessor(Dish newdish)
 {
     if (ModelState.IsValid)
     {
         dbContext.Add(newdish);
         dbContext.SaveChanges();
         return(RedirectToAction("Dishes"));
     }
     return(RedirectToAction("Adddish"));
 }
コード例 #2
0
 public IActionResult CreateDish(Dish newDish)
 {
     if (ModelState.IsValid)
     {
         dbContext.Add(newDish);
         dbContext.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View("New"));
 }
コード例 #3
0
 public IActionResult AddDish(Dish NewDish)
 {
     if (ModelState.IsValid)
     {
         dbContext.Add(NewDish);
         dbContext.SaveChanges();
         return(RedirectToAction("index"));
     }
     else
     {
         return(View("NewForm"));
     }
 }
コード例 #4
0
 public IActionResult Create(Dish newDish)
 {
     if (ModelState.IsValid)
     {
         dbContext.Add(newDish);
         dbContext.SaveChanges();
         return(Redirect("/"));
     }
     else
     {
         return(View("NewDish"));
     }
 }
コード例 #5
0
 public IActionResult CreateDish(Dish fromForm)
 {
     if (ModelState.IsValid)
     {
         _context.Add(fromForm);
         _context.SaveChanges();
         return(RedirectToAction("Index"));
     }
     else
     {
         return(View("DishForm"));
     }
 }
コード例 #6
0
 public IActionResult AddDish(Dishes dish)
 {
     if (ModelState.IsValid)
     {
         dbContext.Add(dish);
         dbContext.SaveChanges();
         return(RedirectToAction("index"));
     }
     else
     {
         // Oh no!  We need to return a ViewResponse to preserve the ModelState, and the errors it now contains!
         return(View("Create"));
     }
 }
コード例 #7
0
ファイル: HomeController.cs プロジェクト: vdaltonrobles/CRUD
 public IActionResult AddDish(Dish newDish)
 {
     if (ModelState.IsValid)
     {
         Console.WriteLine($"***********************{newDish.Chef} | {newDish.Name} | {newDish.Calories} | {newDish.Tastiness} | {newDish.Description}***********************");
         dbContext.Add(newDish);
         dbContext.SaveChanges();
         return(RedirectToAction("Index"));
     }
     else
     {
         return(View("new"));
     }
 }
コード例 #8
0
 public IActionResult AddDish(Dish dish)
 {
     if (ModelState.IsValid)
     {
         Dish newdish = dish;
         dbContext.Add(newdish);
         dbContext.SaveChanges();
         return(RedirectToAction("Index"));
     }
     else
     {
         Console.WriteLine("NOT VALID**************", ModelState.Keys);
         foreach (var error in ModelState)
         {
             if (error.Value.Errors.Count > 0)
             {
                 Console.WriteLine("err msg " + error.Value.Errors[0].ErrorMessage);
             }
         }
         return(RedirectToAction("Add"));
     }
 }
コード例 #9
0
        public IActionResult Create(DishViewModel dish)
        {
            if (!ModelState.IsValid)
            {
                return(View("New"));
            }

            Dish newDish = new Dish
            {
                DishName    = dish.DishName,
                Chef        = dish.Chef,
                Tastiness   = dish.Tastiness,
                Calories    = dish.Calories,
                Description = dish.Description,
                CreatedAt   = DateTime.Now,
                UpdatedAt   = DateTime.Now
            };

            _context.Add(newDish);
            _context.SaveChanges();
            Console.WriteLine("######################################################ADEDD##########################");
            return(RedirectToAction("Index"));
        }
コード例 #10
0
 public IActionResult AddDish(Dish NewDish)
 {
     dbContext.Add(NewDish);
     dbContext.SaveChanges();
     return(RedirectToAction("Index"));
 }