public IHttpActionResult GetTopProduct(TopRequest topRequest)
        {
            DALProduct dalbase  = new DALProduct();
            var        products = dalbase.GetTopProduct(topRequest.DateBegin, topRequest.DateEnd);

            return(Ok(products));
        }
Exemple #2
0
        public static GetAllNewsResponse Execute(TopRequest request)
        {
            var news = DbHelper.GetNewsActive(request.Top);

            news.Sort((a, b) => a.date <= b.date ? 1 : -1);

            var response = new GetAllNewsResponse {
                News = new List <FullNews>()
            };

            if (news == null)
            {
                return(response);
            }

            foreach (var element in news)
            {
                var urlVideo     = DbHelper.GetVideoForNews(element.id_news);
                var img_for_news = DbHelper.GetPhotoForNews(element.id_news);

                var photo = new List <Photo>();

                if (!img_for_news.Any() && element.type == 1)
                {
                    photo.Add(new Photo
                    {
                        Url = "url(./content/img/news.png)"
                    });
                }

                foreach (var item in img_for_news)
                {
                    photo.Add(new Photo
                    {
                        Id  = item.id_img_for_news.ToString(),
                        Url = item.url_bd
                    });
                }

                response.News.Add(new FullNews
                {
                    Id       = element.id_news.ToString(),
                    Title    = element.title,
                    Text     = element.text,
                    Date     = element.date.ToShortDateString(),
                    Type     = element.type,
                    UrlVideo = urlVideo,
                    Photo    = photo
                });
            }

            return(response);
        }
Exemple #3
0
        public async Task TopImageSearchAsyncTotal()
        {
            await LoadData();

            var request = new TopRequest()
            {
                By = "total"
            };

            var topResults = await _searchRepository.TopImageSearchAsync(request, CancellationToken.None);

            Assert.Equal(3, topResults.Count);
        }
Exemple #4
0
        public async Task TopImageSearchAsyncClassification()
        {
            await LoadData();

            var request = new TopRequest()
            {
                By    = "classification",
                Class = Enums.Classes.SafeForWork
            };

            var topResults = await _searchRepository.TopImageSearchAsync(request, CancellationToken.None);

            Assert.Equal(2, topResults.Count);
        }
Exemple #5
0
        public async Task TopImageSearchAsyncSource()
        {
            await LoadData();

            var request = new TopRequest()
            {
                By     = "source",
                Source = Enums.Sources.RedditEarthPorn
            };

            var topResults = await _searchRepository.TopImageSearchAsync(request, CancellationToken.None);

            Assert.Single(topResults);
        }
        public async Task <List <SearchResult> > TopImageSearchAsync(TopRequest topRequest,
                                                                     CancellationToken cancellationToken)
        {
            using (var dbConnection = Connection())
            {
                dbConnection.Open();
                var lookupKeywords = new Dictionary <Guid, Image>();
                var results        = await dbConnection.QueryAsync <Image, Keyword, Image>(_topSql,
                                                                                           (img, keyword) => SqlServerUtilities.FormatSqlResultsData(img, keyword, lookupKeywords),
                                                                                           topRequest
                                                                                           );

                return(results.DistinctBy(i => i.ImageId).Select(image => new SearchResult(image)).ToList());
            }
        }
Exemple #7
0
        public async Task <List <SearchResult> > Source(Enums.Classes id)
        {
            var request = new TopRequest()
            {
                By = "Classification", Class = id
            };

            if (!_settings.Cache.Database)
            {
                return(await _repo.TopImageSearchAsync(request, CancellationToken.None));
            }

            return(await _memoryCache.GetOrCreateAsync($"top:classification:{id}", async cacheEntry => {
                cacheEntry.SetAbsoluteExpiration(new TimeSpan(0, 60, 0));

                return await _repo.TopImageSearchAsync(request, CancellationToken.None);
            }));
        }
Exemple #8
0
        public async Task <List <SearchResult> > Index()
        {
            var request = new TopRequest()
            {
                By = "Total"
            };

            if (!_settings.Cache.Database)
            {
                return(await _repo.TopImageSearchAsync(request, CancellationToken.None));
            }

            return(await _memoryCache.GetOrCreateAsync($"top:total", async cacheEntry => {
                cacheEntry.SetAbsoluteExpiration(new TimeSpan(0, 60, 0));

                return await _repo.TopImageSearchAsync(request, CancellationToken.None);
            }));
        }
Exemple #9
0
 public GetAllNewsResponse GetNewsActive(TopRequest request) => GetNewsActiveBLL.Execute(request);
Exemple #10
0
        public async Task <IActionResult> Post([FromBody] TopRequest title)
        {
            await _hubContext.Clients.All.SendAsync("notification", title);

            return(Ok("Notification sent"));
        }