/// <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 ELearningDatabaseEntitiesServer()) { db.CourseModule.Add(module); db.SaveChanges(); } } catch (InvalidOperationException ex) { throw new CustomException(ex.Message); } }
/// <summary> /// Gets all logs. /// </summary> /// <returns></returns> /// <exception cref="CustomException"></exception> public List<Logs> GetAllLogs() { try { using (var db = new ELearningDatabaseEntitiesServer()) { return db.Logs .OrderBy(x => x.EventDateTime) .ToList(); } } catch (ArgumentNullException ex) { throw new CustomException(ex.Message); } }
/// <summary> /// Gets the log by datetime. /// </summary> /// <param name="datetime">The datetime.</param> /// <returns></returns> /// <exception cref="CustomException"></exception> public List<Logs> GetLogByDatetime(DateTime datetime) { try { using (var db = new ELearningDatabaseEntitiesServer()) { return db.Logs .Where(l => l.EventDateTime.Year == datetime.Year && l.EventDateTime.Month == datetime.Month && l.EventDateTime.Day == datetime.Day) .ToList(); } } catch (ArgumentNullException ex) { throw new CustomException(ex.Message); } }
/// <summary> /// Deletes the log. /// </summary> /// <param name="id">The identifier.</param> /// <exception cref="CustomException"></exception> public void DeleteLog(int id) { try { using (var db = new ELearningDatabaseEntitiesServer()) { Logs log = db.Logs .Where(l => l.Id == id) .FirstOrDefault(); db.Logs .Remove(log); db.SaveChanges(); } } catch (ArgumentNullException ex) { throw new CustomException(ex.Message); } }
/// <summary> /// Deletes the module with the specified identifier. /// </summary> /// <param name="id">The identifier.</param> /// <exception cref="CustomException"> /// </exception> public void DeleteModule(int? id) { try { using (var db = new ELearningDatabaseEntitiesServer()) { CourseModule cm = db.CourseModule .Where(x => x.ModuleId == id) .First(); db.CourseModule.Remove(cm); db.SaveChanges(); } } catch (ArgumentNullException ane) { throw new CustomException(ane.Message); } catch (InvalidOperationException ex) { throw new CustomException(ex.Message); } }
/// <summary> /// Gets the course by identifier. /// </summary> /// <param name="id">The identifier.</param> /// <returns></returns> /// <exception cref="CustomException"></exception> public Courses GetCourseById(int? id) { try { Courses toBeReturned; using (var db = new ELearningDatabaseEntitiesServer()) { toBeReturned = db.Courses .FirstOrDefault(x => x.CourseId == id); } return toBeReturned; } catch (ArgumentNullException ex) { throw new CustomException(ex.Message); } }
/// <summary> /// Gets all modules for the course with the specified identifier. /// </summary> /// <param name="courseId">The course identifier.</param> /// <returns></returns> /// <exception cref="CustomException"></exception> public List<CourseModule> GetAllModules(int? courseId) { try { List<CourseModule> tobeReturned; using (var db = new ELearningDatabaseEntitiesServer()) { tobeReturned = db.CourseModule .Where(x => x.CourseId == courseId) .ToList(); } return tobeReturned; } catch (ArgumentNullException ex) { throw new CustomException(ex.Message); } }
/// <summary> /// Gets all courses. /// </summary> /// <returns></returns> /// <exception cref="CustomException"></exception> public List<Courses> GetAllCourses() { try { List<Courses> courses; using (var db = new ELearningDatabaseEntitiesServer()) { courses = db.Courses .ToList(); } return courses; } catch (ArgumentNullException ane) { throw new CustomException(ane.Message); } }
/// <summary> /// Edits the specified course. /// </summary> /// <param name="course">The course.</param> /// <exception cref="CustomException"></exception> public void Edit(Courses course) { try { using (var db = new ELearningDatabaseEntitiesServer()) { Courses course1 = db.Courses.Where(x => x.CourseId == course.CourseId).First(); db.Courses.Remove(course1); db.SaveChanges(); db.Courses.Add(course); db.SaveChanges(); } } catch (InvalidOperationException ex) { throw new CustomException(ex.Message); } }
/// <summary> /// Gets the logs containing the given information. /// </summary> /// <param name="eventUserLogged">The event containing the given information.</param> /// <returns></returns> /// <exception cref="CustomException"></exception> public List<Logs> GetLogByEventInfo(string eventInfo) { try { using (var db = new ELearningDatabaseEntitiesServer()) { return db.Logs .Where(l => l.EventInfo.Contains(eventInfo)) .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 ELearningDatabaseEntitiesServer()) { return db.Logs .Where(l => l.Id == id) .FirstOrDefault(); } } catch (ArgumentNullException ex) { throw new CustomException(ex.Message); } }
// // GET: /Admin/LogDetails(id = 0) public ActionResult LogDetails(int id = 0) { this.logger.Info("Entering: " + System.Reflection.MethodBase.GetCurrentMethod().ReflectedType.FullName + ": " + System.Reflection.MethodBase.GetCurrentMethod().Name + " --> " + User.Identity.Name); try { using (var db = new ELearningDatabaseEntitiesServer()) { Logs log = this.adminManagement.GetLogById(id); LogsViewModel lvm = this.viewModelFactory.GetViewModel(log); return View(lvm); } } catch (CustomException ce) { this.logger.Trace(ce, "Username: "******"Operation could not be completed!"; return View("Error"); } catch (Exception ex) { this.logger.Trace(ex, "Username: "******"Operation could not be completed!"; return View("Error"); } }
// // GET: /Home/DeleteUsers(id = 0) public ActionResult DeleteUser(int id = 0) { this.logger.Info("Entering: " + System.Reflection.MethodBase.GetCurrentMethod().ReflectedType.FullName + ": " + System.Reflection.MethodBase.GetCurrentMethod().Name + " --> " + User.Identity.Name); try { using (var db = new ELearningDatabaseEntitiesServer()) { Users user = this.userManagement.GetUserById(id); UserProfile userprofile = this.viewModelFactory.GetViewModel(user); return View(userprofile); } } catch (CustomException ce) { this.logger.Trace(ce, "Username: "******"Could not find user!"; return View("Error"); } }