Skip to content

Commit ed97efa

Browse files
committed
Check when the user doesn't have any location in database
1 parent db4403b commit ed97efa

3 files changed

Lines changed: 21 additions & 26 deletions

File tree

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

Lines changed: 18 additions & 20 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,29 +129,27 @@ 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>();
138133

139-
//Get User Location Campaign
140-
foreach (var userLocation in marketingData.Locations)
134+
if (marketingData != null)
141135
{
142-
var userCampaignList = await _context.Rules
143-
.OfType<UserLocationRule>()
144-
.Include(c => c.Campaign)
145-
.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();
150-
151-
if (userCampaignList != null && userCampaignList.Any())
136+
//Get User Location Campaign
137+
foreach (var userLocation in marketingData.Locations)
152138
{
153-
var userCampaignDtoList = MapCampaignModelListToDtoList(userCampaignList);
154-
campaignDtoList.AddRange(userCampaignDtoList);
139+
var userCampaignList = await _context.Rules
140+
.OfType<UserLocationRule>()
141+
.Include(c => c.Campaign)
142+
.Where(c => c.Campaign.From <= DateTime.Now
143+
&& c.Campaign.To >= DateTime.Now
144+
&& c.LocationId == userLocation.LocationId)
145+
.Select(c => c.Campaign)
146+
.ToListAsync();
147+
148+
if (userCampaignList != null && userCampaignList.Any())
149+
{
150+
var userCampaignDtoList = MapCampaignModelListToDtoList(userCampaignList);
151+
campaignDtoList.AddRange(userCampaignDtoList);
152+
}
155153
}
156154
}
157155

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 & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
using Microsoft.EntityFrameworkCore.Query.Internal;
2-
using WebMVC.ViewModels;
3-
41
namespace Microsoft.eShopOnContainers.WebMVC.Controllers
52
{
63
using AspNetCore.Authorization;
@@ -10,6 +7,7 @@ namespace Microsoft.eShopOnContainers.WebMVC.Controllers
107
using System.Threading.Tasks;
118
using System;
129
using ViewModels.Pagination;
10+
using global::WebMVC.ViewModels;
1311

1412
[Authorize]
1513
public class CampaignsController : Controller

0 commit comments

Comments
 (0)