public IActionResult Create(User newuser) { List <string> temp_errors = new List <string>(); if (ModelState.IsValid) { if (userFactory.FindEmail(newuser.email) == null) // Checking email is registered previously { userFactory.Add(newuser); ViewBag.User_Extracting = userFactory.FindByID(); int current_other_id = ViewBag.User_Extracting.id; HttpContext.Session.SetInt32("current_id", (int)current_other_id); ///Inserting into Network table examFactory.Add_Network((int)HttpContext.Session.GetInt32("current_id")); ///Inserting the same user into joiners table by extracting last entered network ViewBag.Network_Extracting = examFactory.Network_Last_ID(); examFactory.Add_Joiner(ViewBag.Network_Extracting.id, (int)HttpContext.Session.GetInt32("current_id")); return(RedirectToAction("Dashboard")); } 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")); }