|
10 | 10 | using System.Collections.Generic; |
11 | 11 | using Microsoft.AspNetCore.Authorization; |
12 | 12 | using System; |
13 | | - using System.Net.Http; |
14 | 13 | using System.Linq; |
15 | | - using System.Net.Http.Headers; |
16 | 14 |
|
17 | 15 | [Route("api/v1/[controller]")] |
18 | 16 | [Authorize] |
@@ -123,14 +121,33 @@ public async Task<IActionResult> Delete(int id) |
123 | 121 | [HttpGet("user/{userId:guid}")] |
124 | 122 | public async Task<IActionResult> GetCampaignsByUserId(Guid userId) |
125 | 123 | { |
126 | | - var userLocation = await _marketingDataRepository.GetAsync(userId.ToString()); |
| 124 | + var marketingData = await _marketingDataRepository.GetAsync(userId.ToString()); |
127 | 125 |
|
128 | | - var userLocationId = 1; |
| 126 | + if (marketingData is null) |
| 127 | + { |
| 128 | + return NotFound(); |
| 129 | + } |
| 130 | + |
| 131 | + var campaignDtoList = new List<CampaignDTO>(); |
129 | 132 |
|
130 | | - var userLocationRule = await _context.Rules.OfType<UserLocationRule>().Include(c => c.Campaign) |
131 | | - .FirstOrDefaultAsync(c => c.LocationId == userLocationId); |
| 133 | + //Get User Location Campaign |
| 134 | + foreach(var userLocation in marketingData.Locations) |
| 135 | + { |
| 136 | + var userCampaignList = await _context.Rules |
| 137 | + .OfType<UserLocationRule>() |
| 138 | + .Include(c => c.Campaign) |
| 139 | + .Where(c => c.LocationId == userLocation.LocationId) |
| 140 | + .Select(c => c.Campaign) |
| 141 | + .ToListAsync(); |
| 142 | + |
| 143 | + if (userCampaignList != null && userCampaignList.Any()) |
| 144 | + { |
| 145 | + var userCampaignDtoList = MapCampaignModelListToDtoList(userCampaignList); |
| 146 | + campaignDtoList.AddRange(userCampaignDtoList); |
| 147 | + } |
| 148 | + } |
132 | 149 |
|
133 | | - return Ok(userLocationRule.Campaign); |
| 150 | + return Ok(campaignDtoList); |
134 | 151 | } |
135 | 152 |
|
136 | 153 |
|
|
0 commit comments