Beispiel #1
0
 public IActionResult CreateChef(Chef newChef)
 {
     if (ModelState.IsValid)
     {
         db.Chefs.Add(newChef);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View("CreateChef", newChef));
 }
        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 #3
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"));
 }
Beispiel #4
0
        public IActionResult DeleteDish(int Id)
        {
            Dish retrievedDish = DbContext.Dishes.FirstOrDefault(dish => dish.Id == Id);

            DbContext.Dishes.Remove(retrievedDish);
            DbContext.SaveChanges();
            List <Dish> dishesWithChefs = DbContext.Dishes
                                          .Include(dish => dish.SubmittedBy)
                                          .ToList();

            return(View("Dishes", dishesWithChefs));
        }
Beispiel #5
0
 public IActionResult CreateChef(Chef chef)
 {
     if (ModelState.IsValid)
     {
         dbContext.Chefs.Add(chef);
         dbContext.SaveChanges();
         return(RedirectToAction("Index"));
     }
     else
     {
         return(View("newChef"));
     }
 }
 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 #7
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"));
        }
Beispiel #8
0
        public IActionResult CreateDish(Dish dish)
        {
            if (ModelState.IsValid)
            {
                if (dbContext.Dishes.Any(d => d.Name == dish.Name && d.Cook == dish.Cook))
                {
                    ModelState.AddModelError("Dish", $"{dish.Cook.FullName}'s {dish.Name} is already in the system");
                    return(View("New"));
                }
                dbContext.Dishes.Add(dish);
                dbContext.SaveChanges();

                return(RedirectToAction("Index"));
            }
            return(View("New"));
        }
 public IActionResult Create(Dish d)
 {
     if (ModelState.IsValid)
     {
         db.Dishes.Add(d);
         db.SaveChanges();
         Console.WriteLine("Model is Valid");
         return(Redirect("/"));
     }
     else
     {
         List <Chef> chef = db.Chefs.ToList();
         ViewBag.All = chef;
         Console.WriteLine("Model is Invalid");
         return(View("Add"));
     }
 }
        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"));
            }
        }
Beispiel #11
0
        public IActionResult CreateCook(Cook cook)
        {
            if (ModelState.IsValid)
            {
                if (dbContext.Cooks.Any(c => c.FullName == cook.FullName))
                {
                    ModelState.AddModelError("Cook", "This cook is already registered");
                    return(RedirectToAction("New"));
                }
                cook.NumberOfDishes = (dbContext.Dishes.Where(d => d.Cook == cook)).Count();
                dbContext.Cooks.Add(cook);
                dbContext.SaveChanges();

                return(RedirectToAction("Home/Index"));
            }
            return(RedirectToAction("New"));
        }