public List <Student> GetAllStudents() { List <Student> students = new List <Student>(); using (StudentDB2Context db = new StudentDB2Context()) { List <Student> std = db.Students.ToList(); List <ListTypesData> ltd = db.ListTypesDatas.Where(x => x.ListTypeId == (int)ListTypes.Gender).ToList(); students = std.Join(ltd, ss => ss.Gender, ld => ld.ListTypeDataId, (ss, ld) => new Student() { StudentId = ss.StudentId, FullName = ss.FullName, GenderDesc = ld.Description, Email = ss.Email, Mobile = ss.Mobile, Telephone = ss.Telephone, Notes = ss.Notes }).ToList(); } return(students); }
public void AddNewStudent(Student student) { using (StudentDB2Context db = new StudentDB2Context()) { db.Students.Add(student); db.SaveChanges(); } }
public Student GetStudentById(int id) { Student student = new Student(); using (StudentDB2Context db = new StudentDB2Context()) { student = db.Students.Where(x => x.StudentId == id).FirstOrDefault(); } return(student); }
public List <StudentsQualification> GetStudentQualificationById(int id) { List <StudentsQualification> qualifications = new List <StudentsQualification>(); using (StudentDB2Context db = new StudentDB2Context()) { qualifications = db.StudentsQualifications.Where(x => x.StudentId == id).ToList(); } return(qualifications); }
// GET: Home public ActionResult Index() { List <Student> students = new List <Student>(); using (StudentDB2Context db = new StudentDB2Context()) { students = db.Students.ToList(); } return(View(students)); }
public ActionResult ReloadStudentDetails(int studentId) { Student student = new Student(); using (StudentDB2Context db = new StudentDB2Context()) { student = db.Students.Find(studentId); } // NewUpdateStudent is the partial view return(PartialView("NewUpdateStudent", student)); }
public static SelectList GetListData(ListTypes listType) { List <SelectListItem> list = new List <SelectListItem>(); using (StudentDB2Context db = new StudentDB2Context()) { list = db.ListTypesDatas.Where(x => x.ListTypeId == (int)listType).Select(x => new SelectListItem { Text = x.Description, Value = x.ListTypeDataId.ToString() }).ToList(); } SelectList lst = new SelectList(list.AsEnumerable(), "Value", "Text"); return(lst); }
public ActionResult Index(Student student) { if (student.StudentId > 0) { using (StudentDB2Context db = new StudentDB2Context()) { db.Entry(student).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } } else { using (StudentDB2Context db = new StudentDB2Context()) { db.Students.Add(student); db.SaveChanges(); } } return(RedirectToAction("Index", "Home")); }