예제 #1
0
        public async Task <Result <IEnumerable <ShowAdvertDto> > > GetAdvertsToShow(CancellationToken ct)
        {
            //количество показываемых кампаний
            const int toShowCount = 4;
            var       adverts     = await _advertRepository.Get(new GetAdvertsParams
            {
                IsBlocked      = false,
                IsOwnerBlocked = false,
                IsVisible      = true,
                ImpressingDate = DateTime.UtcNow,
                ImpressingTime = DateTime.UtcNow.TimeOfDay,
                ToTake         = toShowCount,
                Shuffle        = true
            });

            var toShow = adverts
                         .Select(x => new ShowAdvertDto(x))
                         .ToList();

            if (ct.IsCancellationRequested)
            {
                return(toShow);
            }

            await _statisticRepository.Increment(toShow.Select(x => x.Id), AdvertStatisticType.Impression);

            return(toShow);
        }
예제 #2
0
        public async Task <IActionResult> Index(long?userId)
        {
            var filter = new GetAdvertsParams
            {
                OwnerId = User.GetRole() == Role.Advertiser ? User.GetId() : userId
            };

            IEnumerable <Advert> advertResponses = await _repository.Get(filter);

            return(View(advertResponses.Select(a =>
                                               new AdvertViewModel(a.Id, a.Name, a.IsVisible, a.RequestType, a.OwnerId, a.Owner.Name, a.IsBlocked))));
        }