示例#1
0
        public IActionResult Index(EmailDelegatesViewModel model, string?filterBy = null, string?filterValue = null)
        {
            var delegateUsers = GetDelegateUserCards();

            if (!ModelState.IsValid)
            {
                var newFilterBy   = FilteringHelper.GetFilterBy(filterBy, filterValue, Request, EmailDelegateFilterCookieName);
                var jobGroups     = jobGroupsDataService.GetJobGroupsAlphabetical();
                var customPrompts = centreCustomPromptHelper.GetCustomPromptsForCentre(User.GetCentreId());
                var viewModel     = new EmailDelegatesViewModel(delegateUsers, jobGroups, customPrompts, newFilterBy)
                {
                    SelectedDelegateIds = model.SelectedDelegateIds,
                    Day   = model.Day,
                    Month = model.Month,
                    Year  = model.Year
                };
                return(View(viewModel));
            }

            var    selectedUsers = delegateUsers.Where(user => model.SelectedDelegateIds !.Contains(user.Id)).ToList();
            var    emailDate     = new DateTime(model.Year !.Value, model.Month !.Value, model.Day !.Value);
            string baseUrl       = ConfigHelper.GetAppConfig().GetAppRootPath();

            passwordResetService.SendWelcomeEmailsToDelegates(selectedUsers, emailDate, baseUrl);

            return(View("Confirmation", selectedUsers.Count));
        }
        public IActionResult Index(
            EmailDelegatesFormData formData,
            string?existingFilterString = null,
            string?newFilterToAdd       = null,
            bool clearFilters           = false
            )
        {
            var delegateUsers = GetDelegateUserCards();

            if (!ModelState.IsValid)
            {
                var newFilterString = FilteringHelper.GetFilterString(
                    existingFilterString,
                    newFilterToAdd,
                    clearFilters,
                    Request,
                    EmailDelegateFilterCookieName
                    );
                var jobGroups     = jobGroupsDataService.GetJobGroupsAlphabetical();
                var customPrompts = promptsService.GetCentreRegistrationPrompts(User.GetCentreId());

                var promptsWithOptions = customPrompts.Where(customPrompt => customPrompt.Options.Count > 0);
                var availableFilters   = EmailDelegatesViewModelFilterOptions.GetEmailDelegatesFilterModels(
                    jobGroups,
                    promptsWithOptions
                    );

                var searchSortPaginationOptions = new SearchSortFilterAndPaginateOptions(
                    null,
                    null,
                    new FilterOptions(newFilterString, availableFilters),
                    null
                    );

                var result = searchSortFilterPaginateService.SearchFilterSortAndPaginate(
                    delegateUsers,
                    searchSortPaginationOptions
                    );

                var viewModel = new EmailDelegatesViewModel(result, availableFilters, formData);
                return(View(viewModel));
            }

            var selectedUsers = delegateUsers.Where(user => formData.SelectedDelegateIds !.Contains(user.Id)).ToList();
            var emailDate     = new DateTime(formData.Year !.Value, formData.Month !.Value, formData.Day !.Value);
            var baseUrl       = config.GetAppRootPath();

            passwordResetService.SendWelcomeEmailsToDelegates(selectedUsers, emailDate, baseUrl);

            return(View("Confirmation", selectedUsers.Count));
        }