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> /// 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> /// 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!"); } }