Skip to content

Commit d9db0a6

Browse files
committed
dev merge
1 parent 85c9af6 commit d9db0a6

3 files changed

Lines changed: 12 additions & 16 deletions

File tree

src/Services/Marketing/Marketing.API/Controllers/CampaignsController.cs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
using AspNetCore.Mvc;
88
using Infrastructure;
99
using System.Threading.Tasks;
10-
using Catalog.API.ViewModel;
1110
using Model;
1211
using EntityFrameworkCore;
1312
using Dto;
1413
using AspNetCore.Authorization;
1514
using Extensions.Options;
15+
using Microsoft.eShopOnContainers.Services.Marketing.API.ViewModel;
1616

1717
[Route("api/v1/[controller]")]
1818
[Authorize]
@@ -129,30 +129,26 @@ public async Task<IActionResult> GetCampaignsByUserId(Guid userId, int pageSize
129129
{
130130
var marketingData = await _marketingDataRepository.GetAsync(userId.ToString());
131131

132-
if (marketingData is null)
133-
{
134-
return NotFound();
135-
}
136-
137132
var campaignDtoList = new List<CampaignDTO>();
138-
139-
//Get User Location Campaign
140-
foreach (var userLocation in marketingData.Locations)
133+
134+
if (marketingData != null)
141135
{
136+
var locationIdCandidateList = marketingData.Locations.Select(x => x.LocationId);
142137
var userCampaignList = await _context.Rules
143138
.OfType<UserLocationRule>()
144139
.Include(c => c.Campaign)
145140
.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();
150145

151146
if (userCampaignList != null && userCampaignList.Any())
152147
{
153148
var userCampaignDtoList = MapCampaignModelListToDtoList(userCampaignList);
154149
campaignDtoList.AddRange(userCampaignDtoList);
155150
}
151+
156152
}
157153

158154
var totalItems = campaignDtoList.Count();

src/Services/Marketing/Marketing.API/ViewModel/PaginatedItemsViewModel.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
namespace Microsoft.eShopOnContainers.Services.Catalog.API.ViewModel
1+
namespace Microsoft.eShopOnContainers.Services.Marketing.API.ViewModel
22
{
33
using System.Collections.Generic;
44

5-
65
public class PaginatedItemsViewModel<TEntity> where TEntity : class
76
{
87
public int PageIndex { get; private set; }
@@ -21,4 +20,4 @@ public PaginatedItemsViewModel(int pageIndex, int pageSize, long count, IEnumera
2120
this.Data = data;
2221
}
2322
}
24-
}
23+
}

src/Web/WebMVC/Controllers/CampaignsController.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ namespace Microsoft.eShopOnContainers.WebMVC.Controllers
1010
using System.Threading.Tasks;
1111
using System;
1212
using ViewModels.Pagination;
13+
using global::WebMVC.ViewModels;
1314

1415
[Authorize]
1516
public class CampaignsController : Controller

0 commit comments

Comments
 (0)