/// <summary> /// Gets the associated group by name or description. /// </summary> /// <param name="searchTerm">The search term.</param> /// <param name="userId">The user identifier.</param> /// <returns></returns> /// <exception cref="CustomException"></exception> public List <Groups> GetAssociatedGroupByNameOrDescription(string searchTerm, int userId) { try { using (var db = new ELearningDatabaseEntities()) { var associatedGroups = db.GroupMembers .Where(gm => gm.MemberId == userId) .ToList(); List <Groups> groups = new List <Groups>(); foreach (var myGroup in associatedGroups) { var gr = db.Groups .Where(g => g.GroupId == myGroup.GroupId && (g.GroupDescription.Contains(searchTerm) || g.GroupName.Contains(searchTerm))) .FirstOrDefault(); if (gr != null) { groups.Add(gr); } } return(groups); } } catch (ArgumentNullException ane) { throw new CustomException(ane.Message); } }
/// <summary> /// Gets my courses. /// </summary> /// <param name="id">The user identifier.</param> /// <returns></returns> /// <exception cref="CustomException"></exception> public List <Courses> GetMyCourses(int id) { try { using (var db = new ELearningDatabaseEntities()) { List <Courses> courses = new List <Courses>(); List <int> courseIds = db.UsersInCourse .Where(u => u.UserId == id) .Select(u => u.CourseId) .ToList(); foreach (var x in courseIds) { courses.Add( db.Courses .Where(c => c.CourseId == x) .First() ); } return(courses); } } catch (ArgumentNullException ane) { throw new CustomException(ane.Message); } }
/// <summary> /// Delete a forum with the specified Id /// </summary> /// <param name="id"></param> public void DeleteForum(int?id) { try { using (var db = new ELearningDatabaseEntities()) { List <Messages> messages = db.Messages .Where(x => x.ForumId == id) .ToList(); foreach (Messages m in messages) { db.Messages.Remove(m); db.SaveChanges(); } Forums forum = db.Forums .Where(x => x.ForumId == id) .First(); db.Forums.Remove(forum); db.SaveChanges(); } } catch (ArgumentNullException ane) { throw new CustomException(ane.Message); } catch (InvalidOperationException ex) { throw new CustomException(ex.Message); } }
/// <summary> /// Deletes the group and the members of the group. /// </summary> /// <param name="id">The identifier.</param> /// <exception cref="CustomException"></exception> public void DeleteGroup(int id) { try { using (var db = new ELearningDatabaseEntities()) { //delete the members of the group to be deleted List <GroupMembers> membersOfDeletedGroup = db.GroupMembers .Where(m => m.GroupId == id) .ToList(); foreach (var m in membersOfDeletedGroup) { db.GroupMembers.Remove(m); } db.SaveChanges(); //delete the group Groups group = db.Groups .Where(g => g.GroupId == id) .First(); db.Groups.Remove(group); db.SaveChanges(); } } catch (InvalidOperationException ioe) { throw new CustomException(ioe.Message); } }
public string GetFileIdForAModule(int moduleId) { try { using (var db = new ELearningDatabaseEntities()) { var result = db.Resources .Where(x => x.ModuleID == moduleId) .First(); if (result != null) { return(result.FileId); } } return(string.Empty); } catch (ArgumentNullException ane) { throw new CustomException(ane.Message); } catch (Exception ex) { throw new CustomException(ex.Message); } }
/// <summary> /// Gets all subscribed users to a course. /// </summary> /// <param name="courseId">The course identifier.</param> /// <returns></returns> /// <exception cref="CustomException"></exception> public List <Users> GetAllSubscribedUsers(int courseId) { try { using (var db = new ELearningDatabaseEntities()) { var usersInCourse = db.UsersInCourse .Where(uc => uc.CourseId == courseId) .ToList(); List <Users> users = new List <Users>(); if (usersInCourse != null) { foreach (var user in usersInCourse) { users.Add(db.Users .Where(u => u.UserId == user.UserId) .First() ); } } return(users); } } catch (ArgumentNullException ex) { throw new CustomException(ex.Message); } }
/// <summary> /// Deletes the homework. /// </summary> /// <param name="id">The identifier.</param> /// <exception cref="CustomException"> /// </exception> public void DeleteHomework(int id) { try { using (var db = new ELearningDatabaseEntities()) { //delete the assignements for the homework var assignementsToDelete = db.HomeworkAssignements .Where(a => a.HomeworkId == id) .ToList(); foreach (var a in assignementsToDelete) { db.HomeworkAssignements.Remove(a); } db.SaveChanges(); //delete the homework Homeworks hw = db.Homeworks .Where(h => h.HomeworkId == id) .First(); db.Homeworks.Remove(hw); db.SaveChanges(); } } catch (ArgumentNullException ane) { throw new CustomException(ane.Message); } catch (InvalidOperationException ex) { throw new CustomException(ex.Message); } }
/// <summary> /// Gets the name of the recipient for an assignement. /// </summary> /// <param name="studentId">The student identifier.</param> /// <param name="groupId">The group identifier.</param> /// <returns></returns> /// <exception cref="CustomException"></exception> public string GetRecipientName(int?studentId, int?groupId) { try { using (var db = new ELearningDatabaseEntities()) { string recipient = ""; if (studentId != null && studentId > 0) { var student = db.Users .Where(u => u.UserId == studentId) .First(); recipient = recipient + student.StudentIdentificationNumber + "-" + student.LastName + " " + student.FirstName; if (groupId != null && groupId > 0) { var group = db.Groups .Where(g => g.GroupId == groupId) .First(); recipient = recipient + "; " + group.GroupName; } } else if (groupId != null && groupId > 0) { var group = db.Groups .Where(g => g.GroupId == groupId) .First(); recipient = recipient + group.GroupName; } return(recipient); } } catch (ArgumentNullException ane) { throw new CustomException(ane.Message); } }
/// <summary> /// Deletes the module. /// </summary> /// <param name="id">The identifier.</param> /// <exception cref="CustomException"> /// </exception> public void DeleteModule(int id) { try { using (var db = new ELearningDatabaseEntities()) { var result = db.Resources .First(x => x.ModuleID == id); if (result != null) { var resourceList = db.Resources.Where(x => x.ModuleID == result.ModuleID).ToList(); foreach (var resursa in resourceList) { DeleteFile(resursa.FileId); db.Resources.Remove(resursa); } string fileId = result.FileId; //for drive this.DeleteFile(fileId); db.Resources.Remove(result); db.SaveChanges(); } } } catch (ArgumentNullException ane) { throw new CustomException(ane.Message); } catch (InvalidOperationException ioe) { throw new CustomException(ioe.Message); } catch (Exception ex) { throw new CustomException(ex.Message); } }
/// <summary> /// Gets the associated groups for the given userId. /// </summary> /// <param name="userId">The user identifier.</param> /// <returns></returns> /// <exception cref="CustomException"></exception> public List <Groups> GetAssociatedGroups(int userId) { try { List <Groups> associatedGroups = new List <Groups>(); using (var db = new ELearningDatabaseEntities()) { //get the membership for the userId List <GroupMembers> groupMembers = db.GroupMembers .Where(gm => gm.MemberId == userId) .ToList(); //get all the groups to which the user is subscribed foreach (var gm in groupMembers) { associatedGroups.Add( db.Groups .Where(g => g.GroupId == gm.GroupId) .First() ); } } return(associatedGroups); } catch (ArgumentNullException ane) { throw new CustomException(ane.Message); } }
/// <summary> /// Gets all group members for a given groupId. /// </summary> /// <param name="groupId">The group identifier.</param> /// <returns></returns> /// <exception cref="CustomException"></exception> public List <Users> GetAllGroupMembers(int groupId) { try { List <Users> groupMembers = new List <Users>(); using (var db = new ELearningDatabaseEntities()) { //get the membership for the group List <GroupMembers> membership = db.GroupMembers .Where(gm => gm.GroupId == groupId) .ToList(); //get the users from the group based on the membership foreach (var m in membership) { groupMembers.Add( db.Users .Where(u => u.UserId == m.MemberId) .First() ); } } return(groupMembers); } catch (ArgumentNullException ane) { throw new CustomException(ane.Message); } }
/// <summary> /// Gets all group received grades. /// </summary> /// <param name="groupId">The group identifier.</param> /// <returns></returns> public List <ReceivedGradeDTO> GetAllGroupReceivedGrades(int groupId) { try { List <ReceivedGradeDTO> dtoList = new List <ReceivedGradeDTO>(); using (var db = new ELearningDatabaseEntities()) { var assignements = db.HomeworkAssignements .Where(a => a.GroupId == groupId) .ToList(); foreach (var a in assignements) { var answer = db.Answers .Where(ans => ans.AnswerId == a.AnswerId) .FirstOrDefault(); var grade = db.Grades .Where(g => g.GradeId == a.GradeId) .FirstOrDefault(); var homework = db.Homeworks .Where(h => h.HomeworkId == a.HomeworkId) .FirstOrDefault(); string subject = ""; if (a.CourseId != null && a.CourseId > 0) { subject = db.Courses .Where(c => c.CourseId == a.CourseId) .First() .CourdeCode; } else if (a.CourseModuleId != null && a.CourseModuleId > 0) { subject = db.CourseModule .Where(cm => cm.ModuleId == a.CourseModuleId) .First() .ModuleName; } if (answer != null && grade != null && homework != null) { dtoList.Add(new ReceivedGradeDTO { AnswerId = answer.AnswerId, AnswerValue = answer.AnswerValue, GradeId = grade.GradeId, Gradedatetime = grade.Gradedatetime, GradeValue = grade.GradeValue, HomeworkDeadline = homework.HomeworkDeadline, HomeworkDescription = homework.HomeworkDescription, HomeworkName = homework.HomeworkName, HomeworkPoints = homework.HomeworkPoints, GroupId = groupId, SubjectCode = subject }); } } } return(dtoList); } catch (ArgumentNullException ane) { throw new CustomException(ane.Message); } }
/// <summary> /// Gets all groups. /// </summary> /// <returns></returns> /// <exception cref="CustomException"></exception> public List <Groups> GetAllGroups() { try { using (var db = new ELearningDatabaseEntities()) { return(db.Groups.ToList()); } } catch (ArgumentNullException ane) { throw new CustomException(ane.Message); } }
/// <summary> /// Gets all users. /// </summary> /// <returns></returns> /// <exception cref="CustomException"></exception> public List <Users> GetAllUsers() { try { using (var db = new ELearningDatabaseEntities()) { return(db.Users .ToList()); } } catch (ArgumentNullException ex) { throw new CustomException(ex.Message); } }
/// <summary> /// Saves the resources to database. /// </summary> /// <param name="resources">The resources.</param> /// <exception cref="CustomException"></exception> public void SaveResourcesToDb(Resources resources) { try { using (var db = new ELearningDatabaseEntities()) { db.Resources.Add(resources); db.SaveChanges(); } } catch (Exception ex) { throw new CustomException(ex.Message); } }
/// <summary> /// Deletes all logs. /// </summary> /// <exception cref="CustomException"></exception> public void DeleteAllDisplayedLogs() { try { using (var db = new ELearningDatabaseEntities()) { db.Database.ExecuteSqlCommand("TRUNCATE TABLE Logs"); db.SaveChanges(); } } catch (ArgumentNullException ane) { throw new CustomException(ane.Message); } }
/// <summary> /// Adds the specified module. /// </summary> /// <param name="module">The module.</param> /// <exception cref="CustomException"></exception> public void AddModule(CourseModule module) { try { using (var db = new ELearningDatabaseEntities()) { db.CourseModule.Add(module); db.SaveChanges(); } } catch (InvalidOperationException ex) { throw new CustomException(ex.Message); } }
/// <summary> /// Enrol a student to a course /// </summary> /// <param name= "usersInCourses">The module.</param> /// <exception cref="CustomException"></exception> public void EnrollStudentInCourse(UsersInCourse usersInCourses) { try { using (var db = new ELearningDatabaseEntities()) { db.UsersInCourse.Add(usersInCourses); db.SaveChanges(); } } catch (InvalidOperationException ex) { throw new CustomException(ex.Message); } }
/// <summary> /// Adds the homework. /// </summary> /// <param name="hw">The hw.</param> /// <exception cref="CustomException"></exception> public void AddHomework(Homeworks hw) { try { using (var db = new ELearningDatabaseEntities()) { db.Homeworks.Add(hw); db.SaveChanges(); } } catch (InvalidOperationException ioe) { throw new CustomException(ioe.Message); } }
/// <summary> /// Gets all logs. /// </summary> /// <returns></returns> /// <exception cref="CustomException"></exception> public List <Logs> GetAllLogs() { try { using (var db = new ELearningDatabaseEntities()) { return(db.Logs .OrderBy(x => x.EventDateTime) .ToList()); } } catch (ArgumentNullException ex) { throw new CustomException(ex.Message); } }
/// <summary> /// Edits the specified course. /// </summary> /// <param name="course">The course.</param> /// <exception cref="CustomException"></exception> public void EditCourse(Courses course) { try { using (var db = new ELearningDatabaseEntities()) { db.Courses.Attach(course); db.Entry(course).State = System.Data.EntityState.Modified; db.SaveChanges(); } } catch (InvalidOperationException ex) { throw new CustomException(ex.Message); } }
/// <summary> /// Gets the group by identifier. /// </summary> /// <param name="id">The identifier.</param> /// <returns></returns> /// <exception cref="CustomException"></exception> public Groups GetGroupById(int id) { try { using (var db = new ELearningDatabaseEntities()) { return(db.Groups .Where(g => g.GroupId == id) .First()); } } catch (ArgumentNullException ane) { throw new CustomException(ane.Message); } }
/// <summary> /// Gets the course assignements. /// </summary> /// <param name="id">The identifier.</param> /// <param name="courseId">The course identifier.</param> /// <returns></returns> /// <exception cref="CustomException"></exception> public List <HomeworkAssignements> GetCourseAssignements(int id, int courseId) { try { using (var db = new ELearningDatabaseEntities()) { return(db.HomeworkAssignements .Where(a => a.HomeworkId == id && a.CourseId == courseId) .ToList()); } } catch (ArgumentNullException ane) { throw new CustomException(ane.Message); } }
/// <summary> /// Gets all course homework. /// </summary> /// <param name="courseId">The course identifier.</param> /// <returns></returns> /// <exception cref="CustomException"></exception> public List <Homeworks> GetAllCourseHomework(int courseId) { try { using (var db = new ELearningDatabaseEntities()) { return(db.Homeworks .Where(h => h.CourseId == courseId) .ToList()); } } catch (ArgumentNullException ane) { throw new CustomException(ane.Message); } }
/// <summary> /// Edits the homework. /// </summary> /// <param name="hw">The hw.</param> /// <exception cref="CustomException"></exception> public void EditHomework(Homeworks hw) { try { using (var db = new ELearningDatabaseEntities()) { db.Homeworks.Attach(hw); db.Entry(hw).State = System.Data.EntityState.Modified; db.SaveChanges(); } } catch (InvalidOperationException ex) { throw new CustomException(ex.Message); } }
/// <summary> /// Gets the users by their last name, or the users whose last name starts with the given parameter. /// </summary> /// <param name="lastName">The last name.</param> /// <returns></returns> /// <exception cref="CustomException"></exception> public List <Users> GetUserByLastName(string lastName) { try { using (var db = new ELearningDatabaseEntities()) { return(db.Users .Where(u => u.LastName.Contains(lastName)) .ToList()); } } catch (ArgumentNullException ex) { throw new CustomException(ex.Message); } }
/// <summary> /// Gets the homework by identifier. /// </summary> /// <param name="id">The identifier.</param> /// <returns></returns> /// <exception cref="CustomException"></exception> public Homeworks GetHomeworkById(int id) { try { using (var db = new ELearningDatabaseEntities()) { return(db.Homeworks .Where(h => h.HomeworkId == id) .First()); } } catch (ArgumentNullException ane) { throw new CustomException(ane.Message); } }
/// <summary> /// Gets the log by event level. /// </summary> /// <param name="eventLevel">The event level.</param> /// <returns></returns> /// <exception cref="CustomException"></exception> public List <Logs> GetLogByEventLevel(string eventLevel) { try { using (var db = new ELearningDatabaseEntities()) { return(db.Logs .Where(l => l.EventLevel.Equals(eventLevel)) .ToList()); } } catch (ArgumentNullException ex) { throw new CustomException(ex.Message); } }
/// <summary> /// Gets the log by identifier. /// </summary> /// <param name="id">The identifier.</param> /// <returns></returns> /// <exception cref="CustomException"></exception> public Logs GetLogById(int id) { try { using (var db = new ELearningDatabaseEntities()) { return(db.Logs .Where(l => l.Id == id) .FirstOrDefault()); } } catch (ArgumentNullException ex) { throw new CustomException(ex.Message); } }
/// <summary> /// Gets the user by the username. /// </summary> /// <param name="username">The username.</param> /// <returns></returns> /// <exception cref="CustomException"></exception> public Users GetUserByUserName(string username) { try { using (var db = new ELearningDatabaseEntities()) { return(db.Users .Where(u => u.UserName.Equals(username)) .FirstOrDefault()); } } catch (ArgumentNullException ex) { throw new CustomException(ex.Message); } }