public ActionResult Create(ApplicationForm cr) { var curStud = repository.Applications.FirstOrDefault(x => x.StudentID == cr.StudentID); if (curStud != null) { ViewBag.message = "Student was not created! Such PIN already exists"; List <Class> mod = repository.Classes.ToList(); return(View(mod)); } repository.AddApplication(cr); ViewBag.message = "A new student was successfully added."; List <Class> model = repository.Classes.ToList(); string mail = Request["Email"]; EmailClass obj = new EmailClass(); obj.From = new MailAddress("*****@*****.**"); List <MailAddress> tolist = new List <MailAddress>(); tolist.Add(new MailAddress(mail)); obj.Body = "Thank you for your registration your user name is " + cr.FirstName; obj.to = tolist; obj.Method(); return(RedirectToAction("Info")); //try //{ // // TODO: Add insert logic here // if (ModelState.IsValid) // { // cr.Date = DateTime.Now; // cr.ReadDate = DateTime.Now; // cr.Read = "False"; // db.Applications.Add(cr); // db.SaveChanges(); // } // return RedirectToAction("Info"); //} //catch (Exception ex) //{ // ViewBag.Message = ex.Message; // return View(); //} }
public ActionResult Create(ApplicationForm cr) { var curStud = repository.Applications.FirstOrDefault(x => x.StudentID == cr.StudentID); if (curStud != null) { ViewBag.message = "Student was not created! Such PIN already exists"; List <Class> mod = repository.Classes.ToList(); return(View(mod)); } repository.AddApplication(cr); ViewBag.message = "A new student was successfully added."; List <Class> model = repository.Classes.ToList(); return(RedirectToAction("Info")); //try //{ // // TODO: Add insert logic here // if (ModelState.IsValid) // { // cr.Date = DateTime.Now; // cr.ReadDate = DateTime.Now; // cr.Read = "False"; // db.Applications.Add(cr); // db.SaveChanges(); // } // return RedirectToAction("Info"); //} //catch (Exception ex) //{ // ViewBag.Message = ex.Message; // return View(); //} }