|
7 | 7 | using AspNetCore.Mvc; |
8 | 8 | using Infrastructure; |
9 | 9 | using System.Threading.Tasks; |
10 | | - using Catalog.API.ViewModel; |
11 | 10 | using Model; |
12 | 11 | using EntityFrameworkCore; |
13 | 12 | using Dto; |
14 | 13 | using AspNetCore.Authorization; |
15 | 14 | using Extensions.Options; |
| 15 | + using Microsoft.eShopOnContainers.Services.Marketing.API.ViewModel; |
16 | 16 |
|
17 | 17 | [Route("api/v1/[controller]")] |
18 | 18 | [Authorize] |
@@ -129,30 +129,26 @@ public async Task<IActionResult> GetCampaignsByUserId(Guid userId, int pageSize |
129 | 129 | { |
130 | 130 | var marketingData = await _marketingDataRepository.GetAsync(userId.ToString()); |
131 | 131 |
|
132 | | - if (marketingData is null) |
133 | | - { |
134 | | - return NotFound(); |
135 | | - } |
136 | | - |
137 | 132 | var campaignDtoList = new List<CampaignDTO>(); |
138 | | - |
139 | | - //Get User Location Campaign |
140 | | - foreach (var userLocation in marketingData.Locations) |
| 133 | + |
| 134 | + if (marketingData != null) |
141 | 135 | { |
| 136 | + var locationIdCandidateList = marketingData.Locations.Select(x => x.LocationId); |
142 | 137 | var userCampaignList = await _context.Rules |
143 | 138 | .OfType<UserLocationRule>() |
144 | 139 | .Include(c => c.Campaign) |
145 | 140 | .Where(c => c.Campaign.From <= DateTime.Now |
146 | | - && c.Campaign.To >= DateTime.Now |
147 | | - && c.LocationId == userLocation.LocationId) |
148 | | - .Select(c => c.Campaign) |
149 | | - .ToListAsync(); |
| 141 | + && c.Campaign.To >= DateTime.Now |
| 142 | + && locationIdCandidateList.Contains(c.LocationId)) |
| 143 | + .Select(c => c.Campaign) |
| 144 | + .ToListAsync(); |
150 | 145 |
|
151 | 146 | if (userCampaignList != null && userCampaignList.Any()) |
152 | 147 | { |
153 | 148 | var userCampaignDtoList = MapCampaignModelListToDtoList(userCampaignList); |
154 | 149 | campaignDtoList.AddRange(userCampaignDtoList); |
155 | 150 | } |
| 151 | + |
156 | 152 | } |
157 | 153 |
|
158 | 154 | var totalItems = campaignDtoList.Count(); |
|
0 commit comments