Example #1
0
 public IActionResult NewChef(Chef newChef)
 {
     if (!ModelState.IsValid)
     {
         return(View("NewChef"));
     }
     else
     {
         DateTime now = DateTime.Today;
         if (DateTime.Compare(now, newChef.DateofBirth) < 0)
         {
             ModelState.AddModelError("DateofBirth", "DOB must earlier then current date");
             return(View("NewChef"));
         }
         else
         {
             int age = now.Year - newChef.DateofBirth.Year;
             if (age < 18)
             {
                 ModelState.AddModelError("DateofBirth", "A chef  must older then 18");
                 return(View("NewChef"));
             }
             else
             {
                 dbContext.Chefs.Add(newChef);
                 dbContext.SaveChanges();
                 return(Redirect("/"));
             }
         }
     }
 }
Example #2
0
 public IActionResult CreateChef(Chef chef)
 {
     if (ModelState.IsValid)
     {
         dbContext.Add(chef);
         dbContext.SaveChanges();
         return(RedirectToAction("Index"));
     }
     else
     {
         return(View("New"));
     }
 }
Example #3
0
 public IActionResult ProcessNewChef(Chef newChef)
 {
     if (ModelState.IsValid)
     {
         System.Console.WriteLine($"{newChef.FirstName} | {newChef.LastName}***************************************");
         dbContext.Add(newChef);
         dbContext.SaveChanges();
         return(RedirectToAction("Index"));
     }
     else
     {
         return(View("AddChefForm"));
     }
 }
Example #4
0
 public IActionResult NewChef(Chef newChef)
 {
     if (DateTime.Today.Year - newChef.DOB.Year < 18)
     {
         ModelState.AddModelError("DOB", "Must be 18!");
     }
     if (ModelState.IsValid)
     {
         dbContext.Add(newChef);
         dbContext.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View("AddChef"));
 }
Example #5
0
 public IActionResult NewChefSubmit(User newChef)
 {
     if (ModelState.IsValid)
     {
         DateTime today      = DateTime.Now;
         TimeSpan interval   = today - newChef.DOB;
         Double   totalYears = interval.TotalDays / 365;
         newChef.Age = (int)totalYears;
         dbContext.Add(newChef);
         dbContext.SaveChanges();
         return(RedirectToAction("Index"));
     }
     else
     {
         return(View("NewChef"));
     }
 }
Example #6
0
 public IActionResult ProcessChef(Chef newChef)
 {
     if (ModelState.IsValid)
     {
         int      age    = DateTime.Now.Year - newChef._birthday.Year;
         DateTime date   = newChef._birthday;
         DateTime ageGap = DateTime.Now.AddYears(-18);
         if (date > ageGap)
         {
             string msg = "Chef must be 18!";
             return(RedirectToAction("NewChef", new{ msg = msg }));
         }
         newChef._age = age;
         dbContext.chefs.Add(newChef);
         dbContext.SaveChanges();
         return(RedirectToAction("Index"));
     }
     else
     {
         return(View("NewChef", newChef));
     }
 }
        public IActionResult CreateChef(Chef chef)
        {
            System.Console.WriteLine("Made it to Create chef!!!!!");
            // Checks validations
            if (ModelState.IsValid)
            {
                // If age is greater than or equal to 18 (see Chef.cs)
                if (chef.Age >= 18)
                {
                    Chef newchef = new Chef
                    {
                        FirstName = chef.FirstName,
                        LastName  = chef.LastName,
                        Birthday  = chef.Birthday,
                    };

                    // updates DateTime values
                    chef.CreatedAt = DateTime.Now;
                    chef.UpdatedAt = DateTime.Now;
                    dbContext.Add(newchef);
                    dbContext.SaveChanges();
                    return(RedirectToAction("Index"));
                }
                // Throws Age registration error
                else
                {
                    ModelState.AddModelError("Birthday", "A Chef must be 18 years or older to be registered!");
                    return(View("Index"));
                }
            }
            // Throws ModelState errors
            else
            {
                return(View("Index"));
            }
        }