public IActionResult Index( [Bind(nameof(MainViewData.Scope), nameof(MainViewData.CourseToDisplay), nameof(MainViewData.CourseType), nameof(MainViewData.Order), nameof(MainViewData.Scope))] MainViewData model, int page = 1) { var result = model; List <Announcement> announcements; if (model.Scope == Scope.Courses) { announcements = announcementService.GetAnnouncementsForUserCourses(userManager.GetUserId(User)); } else { announcements = announcementService.GetGeneralAnnouncements(); } result.UsersWithAnnouncements = announcementService.GetUsersWithAnnouncements(); result.Courses = coursesService.GetUserAssignedCourses(userManager.GetUserId(User)) .Select(userCourse => userCourse.Course) .Distinct() .ToList(); if (!string.IsNullOrEmpty(model.CourseToDisplay)) { announcementService.FilterByCourseName(ref announcements, model.CourseToDisplay); } if (model.CourseType.HasValue) { announcementService.FilterByCourseType(ref announcements, model.CourseType.Value); } announcementService.SortAnnouncements(ref announcements, model.Order); result.Announcements = announcements; result.PagingInfo = new PagingInfo { CurrentPage = page, ItemsPerPage = pageSize, TotalItems = result.Announcements.Count() }; result.Announcements = result.Announcements.Skip((page - 1) * pageSize).Take(pageSize).ToList(); return(View(result)); }
public IActionResult Announcements( [Bind(nameof(AdminAnnouncementsViewData.CourseType), nameof(AdminAnnouncementsViewData.AuthorIdToDisplay), nameof(AdminAnnouncementsViewData.CourseToDisplay), nameof(AdminAnnouncementsViewData.Order))] AdminAnnouncementsViewData model, int page = 1) { var result = model; var announcements = announcementsService.GetAllAnnouncements(); result.UsersWithAnnouncements = announcementsService.GetUsersWithAnnouncements(); result.Courses = coursesService.GetAllCourses(); if (model.AuthorIdToDisplay != null) { announcementsService.FilterByAuthor(ref announcements, model.AuthorIdToDisplay); } if (model.CourseType.HasValue) { announcementsService.FilterByCourseType(ref announcements, model.CourseType.Value); } if (!string.IsNullOrEmpty(model.CourseToDisplay)) { announcementsService.FilterByCourseName(ref announcements, model.CourseToDisplay); } announcementsService.SortAnnouncements(ref announcements, model.Order); result.Announcements = announcements; result.PagingInfo = new PagingInfo { CurrentPage = page, ItemsPerPage = pageSize, TotalItems = result.Announcements.Count() }; result.Announcements = result.Announcements.Skip((page - 1) * pageSize).Take(pageSize).ToList(); return(View(result)); }