示例#1
0
 public IActionResult CreateChef(Chef chef)
 {
     if (ModelState.IsValid)
     {
         dbContext.Add(chef);
         dbContext.SaveChanges();
         return(RedirectToAction("Index"));
     }
     else
     {
         return(View("New"));
     }
 }
示例#2
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"));
     }
 }
示例#3
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"));
 }
示例#4
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"));
     }
 }
        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"));
            }
        }