Example #1
0
        public async Task <ActionResult <PaginatedItemsViewModel <CampaignDTO> > > GetCampaignsByUserIdAsync(int pageSize = 10, int pageIndex = 0)
        {
            var userId = _identityService.GetUserIdentity();

            var marketingData = await _marketingDataRepository.GetAsync(userId.ToString());

            var campaignDtoList = new List <CampaignDTO>();

            if (marketingData != null)
            {
                var locationIdCandidateList = marketingData.Locations.Select(x => x.LocationId);
                var userCampaignList        = await _context.Rules
                                              .OfType <UserLocationRule>()
                                              .Include(c => c.Campaign)
                                              .Where(c => c.Campaign.From <= DateTime.Now &&
                                                     c.Campaign.To >= DateTime.Now &&
                                                     locationIdCandidateList.Contains(c.LocationId))
                                              .Select(c => c.Campaign)
                                              .ToListAsync();

                if (userCampaignList != null && userCampaignList.Any())
                {
                    var userCampaignDtoList = MapCampaignModelListToDtoList(userCampaignList);
                    campaignDtoList.AddRange(userCampaignDtoList);
                }
            }

            var totalItems = campaignDtoList.Count();

            campaignDtoList = campaignDtoList
                              .Skip(pageSize * pageIndex)
                              .Take(pageSize).ToList();

            return(new PaginatedItemsViewModel <CampaignDTO>(pageIndex, pageSize, totalItems, campaignDtoList));
        }
        public async Task Handle(UserLocationUpdatedIntegrationEvent @event)
        {
            var userMarketingData = await _marketingDataRepository.GetAsync(@event.UserId);

            userMarketingData = userMarketingData ??
                                new MarketingData()
            {
                UserId = @event.UserId
            };

            userMarketingData.Locations = MapUpdatedUserLocations(@event.LocationList);
            await _marketingDataRepository.UpdateLocationAsync(userMarketingData);
        }
Example #3
0
        public async Task Handle(UserLocationUpdatedIntegrationEvent message, IMessageHandlerContext context)
        {
            var userMarketingData = await _marketingDataRepository.GetAsync(message.UserId);

            userMarketingData = userMarketingData ??
                                new MarketingData()
            {
                UserId = message.UserId
            };

            userMarketingData.Locations = MapUpdatedUserLocations(message.LocationList);
            await _marketingDataRepository.UpdateLocationAsync(userMarketingData);
        }
Example #4
0
        public async Task Handle(UserLocationUpdatedIntegrationEvent @event)
        {
            using (LogContext.PushProperty("IntegrationEventContext", $"{@event.Id}-{Program.AppName}"))
            {
                _logger.LogInformation("----- Handling integration event: {IntegrationEventId} at {AppName} - ({@IntegrationEvent})", @event.Id, Program.AppName, @event);

                var userMarketingData = await _marketingDataRepository.GetAsync(@event.UserId);

                userMarketingData = userMarketingData ??
                                    new MarketingData()
                {
                    UserId = @event.UserId
                };

                userMarketingData.Locations = MapUpdatedUserLocations(@event.LocationList);
                await _marketingDataRepository.UpdateLocationAsync(userMarketingData);
            }
        }