Exemplo n.º 1
0
        public async Task <HttpResponseMessage> Sitemap()
        {
            var xmlWriter  = new SitemapXmlWriter();
            var activities = await _activityOperations.SearchAsync(isChecked : true, page : -1);

            // для активностей формируем урлы
            List <SitemapUrl> urls = GetActivitiesUrls(activities);

            urls.Add(new SitemapUrl
            {
                Priority   = SitemapPagePriority.HIGH,
                ChangeFreq = SitemapPageChangeFrec.DAILY,
                Modified   = DateTimeOffset.Now,
                Url        = _baseUrl + "/"
            });

            urls.Add(new SitemapUrl
            {
                Priority   = SitemapPagePriority.HIGH,
                ChangeFreq = SitemapPageChangeFrec.DAILY,
                Modified   = DateTimeOffset.Now,
                Url        = _baseUrl + "/about"
            });

            urls.Add(new SitemapUrl
            {
                Priority   = SitemapPagePriority.HIGH,
                ChangeFreq = SitemapPageChangeFrec.DAILY,
                Modified   = DateTimeOffset.Now,
                Url        = _baseUrl + "/sponsor"
            });

            urls.Add(new SitemapUrl
            {
                Priority   = SitemapPagePriority.HIGH,
                ChangeFreq = SitemapPageChangeFrec.DAILY,
                Modified   = DateTimeOffset.Now,
                Url        = _baseUrl + "/member"
            });


            // Формируем XML в MemoryStream
            var stream = xmlWriter.CreateXml(urls);
            // Полученный поток преобразуем в файл и отдаём наружу
            var result = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new ByteArrayContent(stream.ToArray())
            };

            result.Content.Headers.ContentDisposition =
                new ContentDispositionHeaderValue("attachment")
            {
                FileName = "sitemap.xml"
            };
            result.Content.Headers.ContentType =
                new MediaTypeHeaderValue("application/xml");
            stream.Close();
            return(result);
        }
Exemplo n.º 2
0
        public async Task <IHttpActionResult> Search(String word    = null,
                                                     int?age        = null,
                                                     int?interestId = null,
                                                     int?cityId     = null,
                                                     bool?sobriety  = null,
                                                     bool?free      = null,
                                                     int page       = 1)
        {
            try
            {
                var activities = await _activityOperations.SearchAsync(word, age, interestId,
                                                                       cityId, sobriety, free, true, page);

                var result = await ViewModelsFromEntities(activities);

                return(Ok(result));
            }
            catch (Exception ex)
            {
                ErrorLogger.Log("CANNOT SEARCH ACTIVITY", ex);
                throw;
            }
        }
Exemplo n.º 3
0
        public void SearchNoParameters_Ok_Test()
        {
            var result = _activityOperations.SearchAsync(null, null, null, null, null, null, false, 1).Result;

            Assert.IsTrue(result.Any());
        }