Example #1
0
 public Student Details(int id = 0)
 {
     using (StudentsDDBBEntities db = new StudentsDDBBEntities())
     {
         return(db.Student.Where(x => x.StudentId == id).FirstOrDefault());
     }
 }
Example #2
0
        public List <Student> GetAllStudents(string SearchBy, string Search, int page, int pageSize)
        {
            using (StudentsDDBBEntities db = new StudentsDDBBEntities())
            {
                List <Student> studentList = new List <Student>();
                page -= 1;
                if (string.IsNullOrEmpty(Search))
                {
                    studentList = db.Student.OrderBy(x => x.StudentId).Skip(page * pageSize).Take(pageSize).ToList();
                }
                else
                {
                    switch (SearchBy)
                    {
                    case "N":
                        studentList = db.Student.Where(x => x.FirstName.Contains(Search)).OrderBy(x => x.StudentId).Skip(page * pageSize).Take(pageSize).ToList();
                        break;

                    case "S":
                        studentList = db.Student.Where(x => x.Surname.Contains(Search)).OrderBy(x => x.StudentId).Skip(page * pageSize).Take(pageSize).ToList();
                        break;

                    case "C":
                        studentList = db.Student.Where(x => x.Course.Contains(Search)).OrderBy(x => x.StudentId).Skip(page * pageSize).Take(pageSize).ToList();
                        break;
                    }
                }
                return(studentList);
            }
        }
Example #3
0
 public int GetAllStudentsCount()
 {
     using (StudentsDDBBEntities db = new StudentsDDBBEntities())
     {
         return(db.Student.Count());
     }
 }
Example #4
0
 public List <Student> GetAllStudents()
 {
     using (StudentsDDBBEntities db = new StudentsDDBBEntities())
     {
         return(db.Student.ToList());
     }
 }
Example #5
0
 public List <Student> Edit(Student student)
 {
     using (StudentsDDBBEntities db = new StudentsDDBBEntities())
     {
         db.Entry(student).State = System.Data.Entity.EntityState.Modified;
         db.SaveChanges();
         return(db.Student.ToList());
     }
 }
Example #6
0
 public List <Student> Create(Student student)
 {
     using (StudentsDDBBEntities db = new StudentsDDBBEntities())
     {
         db.Student.Add(student);
         db.SaveChanges();
         return(db.Student.ToList());
     }
 }
Example #7
0
 public List <Student> Delete(int id = 0)
 {
     using (StudentsDDBBEntities db = new StudentsDDBBEntities())
     {
         Student student = db.Student.Find(id);
         db.Student.Remove(student);
         db.SaveChanges();
         return(db.Student.ToList());
     }
 }