Example #1
0
        public async Task <IActionResult> Index()
        {
            ViewData["Title"] = "Welcome!";

            var pagedResult = await _publicationManager.GetPublications();

            var categories = await _publicationManager.GetCategories();

            var publications = pagedResult.Select(o => new PublicationViewModel(o, _settings.WebSiteUrl, categories));

            var model = new StaticPagedList <PublicationViewModel>(publications, pagedResult);

            return(View(model));
        }
Example #2
0
        public async Task <IActionResult> GetRssFeed()
        {
            var key = "rss";
            var xml = _cache.Get(key)?.ToString();

            if (string.IsNullOrEmpty(xml))
            {
                int?categoryId  = null;
                var pagedResult = await _publicationManager.GetPublications(categoryId, 1, 50);

                var lastUpdateDate = pagedResult.Select(o => o.DateTime).DefaultIfEmpty().Max();

                var rss = new RssDocument
                {
                    Channel =
                        new RssChannel
                    {
                        Copyright   = _settings.WebSiteTitle,
                        Description = _settings.DefaultDescription,
                        SkipDays    = new List <Day>(),
                        SkipHours   = new List <Hour>(),
                        AtomLink    = new RssLink(_settings.RssFeedUrl),
                        Image       = new RssImage
                        {
                            Description = _settings.WebSiteTitle,
                            Height      = 100,
                            Width       = 100,
                            Link        = new RssUrl(_settings.FacebookImage),
                            Title       = _settings.WebSiteTitle,
                            Url         = new RssUrl(_settings.FacebookImage)
                        },
                        Language       = new CultureInfo("ru"),
                        LastBuildDate  = lastUpdateDate,
                        Link           = new RssUrl(_settings.RssFeedUrl),
                        ManagingEditor = new RssPerson("Andrew G.", _settings.SupportEmail),
                        PubDate        = lastUpdateDate,
                        Title          = _settings.WebSiteTitle,
                        TTL            = 10,
                        WebMaster      = new RssPerson("Andrew G.", _settings.SupportEmail),
                        Items          = new List <RssItem> {
                        }
                    }
                };

                foreach (var p in pagedResult)
                {
                    rss.Channel.Items.Add(CreateRssItem(p));
                }

                xml = rss.ToXml();

                _cache.Set(key, xml, TimeSpan.FromMinutes(10));
            }

            return(Content(xml, RssDocument.MimeType));
        }
        public async Task <IActionResult> GetSitemap()
        {
            var page = 1;
            var key  = "sitemap";


            var xml = _cache.Get(key)?.ToString();

            if (string.IsNullOrEmpty(xml))
            {
                IPagedList <Publication> publications;
                IPagedList <Vacancy>     vacancies;

                var sitemap = new Sitemap();
                sitemap.Add(CreateUrl(_settings.WebSiteUrl));
                sitemap.Add(CreateUrl(_settings.WebSiteUrl + "partners/"));

                page = 1;

                do
                {
                    publications = await _publicationManager.GetPublications(null, page);

                    page++;

                    foreach (var p in publications)
                    {
                        var publication = new PublicationViewModel(p, _settings.WebSiteUrl);
                        sitemap.Add(CreateUrl(publication.ShareUrl));
                    }
                }while (publications.HasNextPage);

                page = 1;

                do
                {
                    vacancies = await _vacancyManager.GetVacancies(page);

                    page++;

                    foreach (var v in vacancies)
                    {
                        var vacancy = new VacancyViewModel(v, _settings.WebSiteUrl);
                        sitemap.Add(CreateUrl(vacancy.ShareUrl));
                    }
                }while (vacancies.HasNextPage);

                xml = sitemap.ToXml();
                _cache.Set(key, xml, TimeSpan.FromMinutes(10));
            }


            return(Content(xml, "application/xml"));
        }