public ActionResult Reset_Email(Reset_EmailModel model) { try { if (ModelState.IsValid) { int ID = Convert.ToInt32(Session["Trainer_ID"]); var trainers = db.Trainers.Where(i => i.Email_ID == model.Email && i.ID != ID).FirstOrDefault(); var students = db.Students.Where(i => i.Email_ID == model.Email).FirstOrDefault(); var demo = db.Demoes.Where(i => i.Email_ID == model.Email).FirstOrDefault(); if (trainers == null && students == null && demo == null) { var trainer = db.Trainers.Where(i => i.ID == ID).FirstOrDefault(); if (trainer != null) { trainer.Email_ID = model.Email; db.SaveChanges(); TempData["Success"] = "Email has been reset successfully!! "; if (trainer.Role_ID == 1) { return(RedirectToAction("Owner", "Dashbord")); } if (trainer.Role_ID == 2) { return(RedirectToAction("Manager", "Dashbord")); } } } else { TempData["Error"] = "MailId is alredy registered"; int Trainer_ID = Convert.ToInt32(Session["Trainer_ID"]); var trainer = db.Trainers.Where(i => i.ID == Trainer_ID).FirstOrDefault(); Reset_EmailModel Reset_EmailModel = new Reset_EmailModel(); Reset_EmailModel.Role_ID = Convert.ToInt32(trainer.Role_ID); return(View(Reset_EmailModel)); } } else { TempData["Error"] = "Please Fill All Required Details.!"; int Trainer_ID = Convert.ToInt32(Session["Trainer_ID"]); var trainer = db.Trainers.Where(i => i.ID == Trainer_ID).FirstOrDefault(); Reset_EmailModel Reset_EmailModel = new Reset_EmailModel(); Reset_EmailModel.Role_ID = Convert.ToInt32(trainer.Role_ID); return(View(Reset_EmailModel)); } return(View()); } catch (Exception ex) { return(RedirectToAction("Contact", "Home")); } }
public ActionResult Reset_Email() { try { int ID = Convert.ToInt32(Session["Trainer_ID"]); var trainer = db.Trainers.Where(i => i.ID == ID).FirstOrDefault(); Reset_EmailModel Reset_EmailModel = new Reset_EmailModel(); Reset_EmailModel.Role_ID = Convert.ToInt32(trainer.Role_ID); return(View(Reset_EmailModel)); } catch (Exception ex) { return(RedirectToAction("Contact", "Home")); } }