Пример #1
0
        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));
        }