public ActionResult AddNewRotationStudent(FormCollection formCollection) { if (Session["Email"] != null) { string email = (string)Session["Email"]; StudentContext studentContext = new StudentContext(); Student student = studentContext.Students.Single(e => e.Email.Equals(email)); RotationListContext rotationListContext = new RotationListContext(); RotationList rotationList = new RotationList(); rotationList.StudentName = formCollection["StudentName"]; rotationList.StudentId = student.ID; rotationList.Start = formCollection["Start"]; rotationList.End = formCollection["End"]; rotationList.Supervisor = formCollection["Supervisors"]; rotationList.Type = formCollection["Rotations"]; rotationListContext.RotationList.Add(rotationList); rotationListContext.SaveChanges(); return(RedirectToAction("StudentPage", "Student")); } return(RedirectToAction("Index", "Home")); }
public ActionResult Edit(FormCollection formCollection, int?id) { if (Session["Email"] != null) { if (id != null) { RotationListContext context = new RotationListContext(); RotationList rotationLists = context.RotationList.Single(pro => pro.Id == id); rotationLists.StudentName = formCollection["StudentName"]; rotationLists.Type = formCollection["Type"]; rotationLists.Start = formCollection["Start"]; rotationLists.End = formCollection["End"]; rotationLists.Supervisor = formCollection["Supervisor"]; context.SaveChanges(); return(RedirectToAction("Index")); } else { return(RedirectToAction("Index", "RotationList")); } } return(RedirectToAction("Index", "Home")); }
public ActionResult Index(string option, string search) { if (Session["Email"] != null) { RotationListContext context = new RotationListContext(); //if a user choose the radio button option as Subject if (option == "Name") { //Index action method will return a view with a student records based on what a user specify the value in textbox return(View(context.RotationList.Where(x => x.StudentName == search || search == null).ToList())); } else if (option == "Type") { return(View(context.RotationList.Where(x => x.Type == search || search == null).ToList())); } else if (option == "Start") { return(View(context.RotationList.Where(x => x.Start == search || search == null).ToList())); } else { return(View(context.RotationList.Where(x => x.End.StartsWith(search) || search == null).ToList())); } } return(RedirectToAction("Index", "Home")); }
public ActionResult Index() { RotationListContext context = new RotationListContext(); List <RotationList> rotationLists = context.RotationList.ToList(); return(View()); }
public ActionResult RegistrationForm(Models.RegisterFormModel formData) { if (ModelState.IsValid) { using (SqlConnection con = new SqlConnection(CS)) { con.Open(); string secCode = generateSecurityCode(); StudentContext studentContext = new StudentContext(); Student student = new Student(); try { student.FirstName = formData.FirstName; student.LastName = formData.LastName; student.Address = formData.Address; student.PostalCode = formData.PostalCode; student.DOB = formData.DOB; student.Email = formData.Email; student.Password = formData.Password; student.Phone = formData.Phone; student.ProgramName = formData.ProgramName; student.InstitutionName = formData.InstitutionName; student.ProgramType = formData.ProgramType; student.SecurityCode = secCode; } catch (Exception e) { Console.WriteLine(e); } studentContext.Students.Add(student); studentContext.SaveChanges(); Session["FirstName"] = student.FirstName; Session["id"] = student.ID; RotationListContext rotationListContext = new RotationListContext(); RotationList rotationList = new RotationList(); rotationList.StudentName = student.LastName + ", " + student.FirstName; rotationList.StudentId = student.ID; rotationList.Start = formData.StartDate; rotationList.End = formData.EndDate; rotationList.Supervisor = formData.RotationSupervisors; rotationList.Type = formData.Rotations; rotationListContext.RotationList.Add(rotationList); rotationListContext.SaveChanges(); } return(RedirectToAction("StudentPage", "Student")); } else { //return View("Index"); return(RedirectToAction("Index", "Registration")); } }
public ActionResult ExportView() { if (Session["Email"] != null) { RotationListContext context = new RotationListContext(); List <RotationList> rotationLists = context.RotationList.ToList(); Response.AddHeader("content-disposition", "attachment;filename=Report1.xls"); Response.AddHeader("Content-Type", "application/vnd.ms-excel"); return(View(rotationLists)); } return(RedirectToAction("Index", "Home")); }
public ActionResult EditRotationStudent(RotationList rotationList) { if (Session["Email"] != null) { RotationListContext rotationListContext = new RotationListContext(); rotationListContext.Entry(rotationList).State = System.Data.Entity.EntityState.Modified; rotationListContext.SaveChanges(); return(RedirectToAction("StudentPage", "Student")); } return(RedirectToAction("Index", "Home")); }
public ActionResult Edit(int?id) { if (Session["Email"] != null) { if (id != null) { RotationListContext context = new RotationListContext(); RotationList rotationList = context.RotationList.Single(pro => pro.Id == id); return(View(rotationList)); } else { return(RedirectToAction("Index", "RotationList")); } } return(RedirectToAction("Index", "Home")); }
public ActionResult StudentPage() { if (Session["Email"] != null) { ViewBag.FirstName = Session["FirstName"]; StudentContext studentContext = new StudentContext(); string email = (string)Session["Email"]; Student student = studentContext.Students.Single(e => e.Email.Equals(email)); RotationListContext rotationListContext = new RotationListContext(); List <RotationList> rotationsList = rotationListContext.RotationList.Where(e => e.StudentId == student.ID).ToList(); return(View(rotationsList)); } return(RedirectToAction("Index", "Home")); }
public ActionResult DeleteRotationStudent(int?id) { if (Session["Email"] != null) { if (id != null) { RotationListContext rotationListContext = new RotationListContext(); RotationList rotationList = rotationListContext.RotationList.Single(e => e.Id == id); return(View(rotationList)); } else { return(RedirectToAction("StudentPage", "Student")); } } return(RedirectToAction("Index", "Home")); }
public ActionResult Create(FormCollection formCollection) { if (Session["Email"] != null) { RotationList rotationLists = new RotationList(); RotationListContext context = new RotationListContext(); rotationLists.StudentName = formCollection["StudentName"]; rotationLists.Type = formCollection["Type"]; rotationLists.Start = formCollection["Start"]; rotationLists.End = formCollection["End"]; rotationLists.Supervisor = formCollection["Supervisor"]; context.RotationList.Add(rotationLists); context.SaveChanges(); return(RedirectToAction("Index")); } return(RedirectToAction("Index", "Home")); }
public ActionResult Delete(int?id, FormCollection formCollection) { if (Session["Email"] != null) { if (id != null) { RotationListContext context = new RotationListContext(); RotationList rotationLists = context.RotationList.Single(pro => pro.Id == id); context.RotationList.Remove(rotationLists); context.SaveChanges(); return(RedirectToAction("Index")); } else { return(RedirectToAction("Index", "RotationList")); } } return(RedirectToAction("Index", "Home")); }
public ActionResult EditRotationStudent(int?id) { if (Session["Email"] != null) { if (id != null) { string email = (string)Session["Email"]; Student student = getStudentInfo(email); RotationListContext rotationListContext = new RotationListContext(); RotationList rotationList = rotationListContext.RotationList.Single(e => e.Id == id); List <String> rotationsList = new List <String>(); List <String> rotationSupervisorsList = new List <String>(); using (var connection = new SqlConnection(CS)) { string commandText = "SELECT DISTINCT Rotations FROM [Rotations]"; using (var command = new SqlCommand(commandText, connection)) { connection.Open(); using (SqlDataReader sdr = command.ExecuteReader()) { while (sdr.Read()) { rotationsList.Add(Convert.ToString(sdr[0])); } } connection.Close(); } commandText = "SELECT DISTINCT Supervisor FROM [Rotations]"; using (var command = new SqlCommand(commandText, connection)) { connection.Open(); using (SqlDataReader sdr = command.ExecuteReader()) { while (sdr.Read()) { rotationSupervisorsList.Add(Convert.ToString(sdr[0])); } } connection.Close(); } } SelectList selectRotations = new SelectList(rotationsList, "id"); SelectList selectRotationSupervisors = new SelectList(rotationSupervisorsList, "id"); ViewBag.Student = student.LastName + ", " + student.FirstName; ViewBag.Rotations = selectRotations; ViewBag.Supervisors = selectRotationSupervisors; return(View(rotationList)); } else { return(RedirectToAction("StudentPage", "Student")); } } return(RedirectToAction("Index", "Home")); }