public async Task <IActionResult> Index(PagerParameters pagerParameters)
        {
            if (!await _authorizationService.AuthorizeAsync(User, EmailTemplatesPermissions.ManageEmailTemplates))
            {
                return(Unauthorized());
            }

            var siteSettings = await _siteService.GetSiteSettingsAsync();

            var pager             = new Pager(pagerParameters, siteSettings.PageSize);
            var templatesDocument = await _emailTemplatesManager.GetTemplatesDocumentAsync();


            var count = templatesDocument.Templates.Count;

            var templates = templatesDocument.Templates.OrderBy(x => x.Key)
                            .Skip(pager.GetStartIndex())
                            .Take(pager.PageSize);

            var pagerShape = (await New.Pager(pager)).TotalItemCount(count);

            var model = new EmailTemplateIndexViewModel
            {
                Templates = templates.Select(x => new TemplateEntry {
                    Name = x.Key, Template = x.Value
                }).ToList(),
                Pager = pagerShape
            };

            return(View("Index", model));
        }
Example #2
0
        public async Task <IActionResult> Index(ViewModels.ContentOptions options, PagerParameters pagerParameters)
        {
            if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageEmailTemplates))
            {
                return(Forbid());
            }

            var siteSettings = await _siteService.GetSiteSettingsAsync();

            var pager             = new Pager(pagerParameters, siteSettings.PageSize);
            var templatesDocument = await _templatesManager.GetEmailTemplatesDocumentAsync();

            var templates = templatesDocument.Templates.ToList();

            if (!string.IsNullOrWhiteSpace(options.Search))
            {
                templates = templates.Where(x => x.Value.Name.Contains(options.Search, StringComparison.OrdinalIgnoreCase)).ToList();
            }

            var count = templates.Count;

            templates = templates.OrderBy(x => x.Value.Name)
                        .Skip(pager.GetStartIndex())
                        .Take(pager.PageSize).ToList();

            var pagerShape = (await New.Pager(pager)).TotalItemCount(count);

            var model = new EmailTemplateIndexViewModel
            {
                Templates = templates.ConvertAll(x => new TemplateEntry {
                    Id = x.Key, Template = x.Value
                }),
                Options = options,
                Pager   = pagerShape
            };

            model.Options.ContentsBulkAction = new List <SelectListItem>()
            {
                new SelectListItem()
                {
                    Text = S["Delete"], Value = nameof(ContentsBulkAction.Remove)
                }
            };

            return(View("Index", model));
        }