Esempio n. 1
0
        public IActionResult Announcements(
            [Bind(nameof(UserAnnouncementsViewData.CourseToDisplay),
                  nameof(UserAnnouncementsViewData.CourseType),
                  nameof(UserAnnouncementsViewData.Order))] UserAnnouncementsViewData model,
            int page = 1)
        {
            int pageSize      = 5;
            var viewModel     = new UserAnnouncementsViewData();
            var announcements = announcementsService.GetUserAnnouncements(userManager.GetUserId(User));

            if (!string.IsNullOrEmpty(model.CourseToDisplay))
            {
                viewModel.CourseToDisplay = model.CourseToDisplay;
                announcementsService.FilterByCourseName(ref announcements, model.CourseToDisplay);
            }
            if (model.CourseType.HasValue)
            {
                viewModel.CourseType = model.CourseType.Value;
                announcementsService.FilterByCourseType(ref announcements, model.CourseType.Value);
            }
            announcementsService.SortAnnouncements(ref announcements, model.Order);
            viewModel.Announcements = announcements;
            viewModel.PagingInfo    = new PagingInfo
            {
                CurrentPage  = page,
                ItemsPerPage = pageSize,
                TotalItems   = viewModel.Announcements.Count
            };
            viewModel.Announcements = viewModel.Announcements.Skip((page - 1) * pageSize).Take(pageSize).ToList();
            viewModel.Courses       = coursesService.GetUserCourses(userManager.GetUserId(User));
            return(View(viewModel));
        }
Esempio n. 2
0
        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));
        }
Esempio n. 3
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));
        }