public List<Admin> GetAllAdmins()
 {
     using (var context = new DB_ELearningEntities())
     {
         var list = context.Admins.ToList();
         return list;
     }
 }
 /// <summary>
 /// Gets all assistants.
 /// </summary>
 /// <returns>list of assistants</returns>
 public List<Assistant> GetAllAssistants()
 {
     using (var context = new DB_ELearningEntities())
     {
         var list = context.Assistants.ToList();
         return list;
     }
 }
 /// <summary>
 /// Gets all students.
 /// </summary>
 /// <returns>List&lt;Student&gt;.</returns>
 public List<Student> GetAllStudents()
 {
     using (var context = new DB_ELearningEntities())
     {
         var list = context.Students.ToList();
         return list;
     }
 }
 public List<Teacher> GetAllTeachers()
 {
     using (var context = new DB_ELearningEntities())
     {
         var list = context.Teachers.ToList();
         return list;
     }
 }
 public ActionResult Index()
 {
     ViewBag.Message = "Modify this template to jump-start your ASP.NET MVC application.";
     var list = new DB_ELearningEntities().Admins;
     if (list.ToList().Count > 0)
         return View();
     else return View();
 }
 public Teacher GetByID(int teacherID)
 {
     using (var context = new DB_ELearningEntities())
     {
         var prof = context.Teachers.Where(teacher => teacher.TeacherID == teacherID).First();
         if (prof == null)
             throw new Exception("No teacher with given ID found!");
         else return prof;
     }
 }
        public void CreateAdmin(string email)
        {
            using (var context = new DB_ELearningEntities())
            {
                var newAdmin = context.Admins.Create();
                newAdmin.Email = email;

                context.Admins.Attach(newAdmin);
                context.SaveChanges();
            }
        }
        public void EditTeacher(int teacherID, string firstName, string LastName, string email)
        {
            using (var context = new DB_ELearningEntities())
            {
                var prof = context.Teachers.Where(teacher => teacher.TeacherID == teacherID).First();
                prof.FirstName = firstName;
                prof.LastName = LastName;
                prof.Email = email;

                context.SaveChanges();
            }
        }
 /// <summary>
 /// Deletes the student.
 /// </summary>
 /// <param name="studentID">The student identifier.</param>
 /// <exception cref="NullReferenceException">Student with this id not found!</exception>
 public void DeleteStudent(int studentID)
 {
     using (var context = new DB_ELearningEntities())
     {
         var studentToDelete = context.Students.Where(student => student.StudentID == studentID).FirstOrDefault();
         if (studentToDelete != null)
         {
             context.Students.Remove(studentToDelete);
             context.SaveChanges();
         }
         else throw new NullReferenceException("Student with this id not found!");
     }
 }
        public void CreateTeacher(string firstName, string LastName, string email)
        {
            using (var context = new DB_ELearningEntities())
            {
                var newTeacher = context.Teachers.Create();
                newTeacher.FirstName = firstName;
                newTeacher.LastName = LastName;
                newTeacher.Email = email;

                context.Teachers.Attach(newTeacher);
                context.SaveChanges();
            }
        }
        /// <summary>
        /// Adds the assistant.
        /// </summary>
        /// <param name="firstName">The first name.</param>
        /// <param name="lastName">The last name.</param>
        /// <param name="email">The email.</param>
        public void AddAssistant(string firstName, string lastName, string email)
        {
            using (var context = new DB_ELearningEntities())
            {
                var newAssistant = context.Assistants.Create();
                newAssistant.Email = email;
                newAssistant.FirstName = firstName;
                newAssistant.LastName = lastName;

                context.Assistants.Attach(newAssistant);
                context.SaveChanges();
            }
        }
 public void DeleteTeacher(int teacherID)
 {
     using (var context = new DB_ELearningEntities())
     {
         var prof = context.Teachers.Where(teacher => teacher.TeacherID == teacherID).First();
         if (prof == null)
             throw new Exception("Teacher with given ID not found!");
         else
         {
             context.Teachers.Remove(prof);
             context.SaveChanges();
         }
     }
 }
 /// <summary>
 /// Blocks/Unblocks the student with the given student id.
 /// </summary>
 /// <param name="studentID">The student identifier.</param>
 /// <exception cref="NullReferenceException">Student with this id not found!</exception>
 public void ToggleBlock(int studentID)
 {
     using (var context = new DB_ELearningEntities())
     {
         var studentToBlock = context.Students.Where(student => student.StudentID == studentID).FirstOrDefault();
         if (studentToBlock != null)
         {
             if (studentToBlock.isBlocked == null || studentToBlock.isBlocked == false)
                 studentToBlock.isBlocked = true;
             else
                 studentToBlock.isBlocked = false;
             context.SaveChanges();
         }
         else throw new NullReferenceException("Student with this id not found!");
     }
 }
        /// <summary>
        /// Edits the assistant.
        /// </summary>
        /// <param name="assistantID">The assistant identifier.</param>
        /// <param name="firstName">The first name.</param>
        /// <param name="lastName">The last name.</param>
        /// <param name="email">The email.</param>
        /// <exception cref="NullReferenceException">Assistant with this id not found!</exception>
        public void EditAssistant(int assistantID, string firstName, string lastName, string email)
        {
            using (var context = new DB_ELearningEntities())
            {
                var assistantToEdit = context.Assistants.Where(assistant => assistant.AssistantID == assistantID).FirstOrDefault();
                if (assistantToEdit != null)
                {
                    assistantToEdit.Email = email;
                    assistantToEdit.FirstName = firstName;
                    assistantToEdit.LastName = lastName;

                    context.SaveChanges();
                }
                else throw new NullReferenceException("Assistant with this id not found!");
            }
        }
        /// <summary>
        /// Adds the student.
        /// </summary>
        /// <param name="userID">The user identifier.</param>
        /// <param name="firstName">The first name.</param>
        /// <param name="lastName">The last name.</param>
        /// <param name="address">The address.</param>
        /// <param name="email">The email.</param>
        /// <param name="cardNO">The card number.</param>
        public void AddStudent(int userID, string firstName, string lastName, string address, string email, string cardNO)
        {
            using (var context = new DB_ELearningEntities())
            {
                var newStudent = context.Students.Create();
                newStudent.Address = address;
                newStudent.CardNO = cardNO;
                newStudent.Email = email;
                newStudent.FirstName = firstName;
                newStudent.isBlocked = false;
                newStudent.LastName = lastName;
                newStudent.UserID = userID;

                context.Students.Attach(newStudent);
                context.SaveChanges();
            }
        }
        /// <summary>
        /// Gets the assistant by identifier.
        /// </summary>
        /// <param name="assistantID">The assistant identifier.</param>
        /// <returns>assistant with given id</returns>
        /// <exception cref="Exception">Assistant with this id not found!</exception>
        public Assistant GetAssistantById(int assistantID)
        {
            using (var context = new DB_ELearningEntities())
            {
                var assistantToGet = context.Assistants.Where(assistant => assistant.AssistantID == assistantID).FirstOrDefault();
                if (assistantToGet != null)
                    return assistantToGet;

                else throw new Exception("Assistant with this id not found!");
            }
        }