public IActionResult CreateDish(Dish NewDish, int FormChefId)
        {
            Chef ChefSelected = dbContext.Chef.FirstOrDefault(c => c.ChefId == FormChefId);

            NewDish.ChefId = FormChefId;
            dbContext.Add(NewDish);
            dbContext.SaveChanges();


            return(RedirectToAction("ShowDishes"));
        }
Beispiel #2
0
 public IActionResult AddChef(Chef newChef)
 {
     if (ModelState.IsValid)
     {
         db.Add(newChef);
         db.SaveChanges();
         return(RedirectToAction("Chefs"));
     }
     // if validations do not pass, go back to form page
     // to display validation errors
     return(View("CreateChef"));
 }
 public IActionResult CreateChef(Chef newChef)
 {
     if (ModelState.IsValid)
     {
         if (newChef.Age() < 18)
         {
             ModelState.AddModelError("BirthDate", "Must be 18 years of age");
             return(View("NewChef"));
         }
         dbContext.Add(newChef);
         dbContext.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(RedirectToAction("NewChef"));
 }
Beispiel #4
0
        public IActionResult CreateChef(Chef newChef)
        {
            if (ModelState.IsValid)
            {
                if (newChef.DOB > DateTime.Today)
                {
                    ModelState.AddModelError("DOB", "Date cannot be a futur date.");
                    return(View("NewChef"));
                }

                db.Add(newChef);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View("NewChef"));
        }
        public IActionResult CreateNewChef(Chef newChef)
        {
            DateTime today   = DateTime.Now;
            int      calcage = today.Year - newChef.DateOfBirth.Year;

            newChef.Age = calcage;
            if (calcage < 18)
            {
                System.Console.WriteLine($"INSIDE DATEOFBIRTH IF **************************");
                ModelState.AddModelError("DateOfBirth", "Chef must be at least 18 years old");
                return(View("NewChef"));
            }
            if (ModelState.IsValid)
            {
                dbContext.Add(newChef);
                dbContext.SaveChanges();
                return(Redirect("/"));
            }
            else
            {
                return(View("NewChef"));
            }
        }