コード例 #1
0
        public IActionResult Create(User newuser)
        {
            Console.WriteLine("birthday is" + newuser.birthday);
            List <string> temp_errors = new List <string>();

            if (ModelState.IsValid)
            {
                if (travelFactory.FindEmail(newuser.email) == null) // Checking email is registered previously
                {
                    if (newuser.birthday < DateTime.Today)          //checking date is in past or not
                    {
                        travelFactory.Add(newuser);
                        ViewBag.User_Extracting = travelFactory.FindByID();
                        int current_other_id = ViewBag.User_Extracting.id;
                        HttpContext.Session.SetInt32("current_id", (int)current_other_id);
                        return(RedirectToAction("Dashboard"));
                    }
                    else
                    {
                        temp_errors.Add("Birthday date must be in past");
                        TempData["errors"] = temp_errors;
                        return(RedirectToAction("Index"));
                    }
                }
                else
                {
                    temp_errors.Add("Email is already in use");
                    TempData["errors"] = temp_errors;
                    return(RedirectToAction("Index"));
                }
            }
            foreach (var error in ModelState.Values)
            {
                if (error.Errors.Count > 0)
                {
                    temp_errors.Add(error.Errors[0].ErrorMessage);
                }
            }
            TempData["errors"] = temp_errors;
            return(RedirectToAction("Index"));
        }