|
@ -1,17 +1,18 @@ |
|
|
namespace Microsoft.eShopOnContainers.Services.Marketing.API.Controllers |
|
|
namespace Microsoft.eShopOnContainers.Services.Marketing.API.Controllers |
|
|
{ |
|
|
{ |
|
|
using Infrastructure.Repositories; |
|
|
|
|
|
using Microsoft.AspNetCore.Mvc; |
|
|
|
|
|
using Microsoft.eShopOnContainers.Services.Marketing.API.Infrastructure; |
|
|
|
|
|
using System.Threading.Tasks; |
|
|
|
|
|
using Microsoft.eShopOnContainers.Services.Marketing.API.Model; |
|
|
|
|
|
using Microsoft.EntityFrameworkCore; |
|
|
|
|
|
using Microsoft.eShopOnContainers.Services.Marketing.API.Dto; |
|
|
|
|
|
using System.Collections.Generic; |
|
|
|
|
|
using Microsoft.AspNetCore.Authorization; |
|
|
|
|
|
using System; |
|
|
using System; |
|
|
using System.Linq; |
|
|
using System.Linq; |
|
|
using Microsoft.Extensions.Options; |
|
|
|
|
|
|
|
|
using System.Collections.Generic; |
|
|
|
|
|
using Infrastructure.Repositories; |
|
|
|
|
|
using AspNetCore.Mvc; |
|
|
|
|
|
using Infrastructure; |
|
|
|
|
|
using System.Threading.Tasks; |
|
|
|
|
|
using Catalog.API.ViewModel; |
|
|
|
|
|
using Model; |
|
|
|
|
|
using EntityFrameworkCore; |
|
|
|
|
|
using Dto; |
|
|
|
|
|
using AspNetCore.Authorization; |
|
|
|
|
|
using Extensions.Options; |
|
|
|
|
|
|
|
|
[Route("api/v1/[controller]")]
|
|
|
[Route("api/v1/[controller]")]
|
|
|
[Authorize] |
|
|
[Authorize] |
|
@ -124,7 +125,7 @@ |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[HttpGet("user/{userId:guid}")] |
|
|
[HttpGet("user/{userId:guid}")] |
|
|
public async Task<IActionResult> GetCampaignsByUserId(Guid userId) |
|
|
|
|
|
|
|
|
public async Task<IActionResult> GetCampaignsByUserId(Guid userId, int pageSize = 10, int pageIndex = 0) |
|
|
{ |
|
|
{ |
|
|
var marketingData = await _marketingDataRepository.GetAsync(userId.ToString()); |
|
|
var marketingData = await _marketingDataRepository.GetAsync(userId.ToString()); |
|
|
|
|
|
|
|
@ -136,13 +137,13 @@ |
|
|
var campaignDtoList = new List<CampaignDTO>(); |
|
|
var campaignDtoList = new List<CampaignDTO>(); |
|
|
|
|
|
|
|
|
//Get User Location Campaign
|
|
|
//Get User Location Campaign
|
|
|
foreach(var userLocation in marketingData.Locations) |
|
|
|
|
|
|
|
|
foreach (var userLocation in marketingData.Locations) |
|
|
{ |
|
|
{ |
|
|
var userCampaignList = await _context.Rules |
|
|
var userCampaignList = await _context.Rules |
|
|
.OfType<UserLocationRule>() |
|
|
.OfType<UserLocationRule>() |
|
|
.Include(c => c.Campaign) |
|
|
.Include(c => c.Campaign) |
|
|
.Where(c => c.Campaign.From <= DateTime.Now |
|
|
.Where(c => c.Campaign.From <= DateTime.Now |
|
|
&& c.Campaign.To >= DateTime.Now |
|
|
|
|
|
|
|
|
&& c.Campaign.To >= DateTime.Now |
|
|
&& c.LocationId == userLocation.LocationId) |
|
|
&& c.LocationId == userLocation.LocationId) |
|
|
.Select(c => c.Campaign) |
|
|
.Select(c => c.Campaign) |
|
|
.ToListAsync(); |
|
|
.ToListAsync(); |
|
@ -154,7 +155,15 @@ |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return Ok(campaignDtoList); |
|
|
|
|
|
|
|
|
var totalItems = campaignDtoList.Count(); |
|
|
|
|
|
campaignDtoList = campaignDtoList |
|
|
|
|
|
.Skip(pageSize * pageIndex) |
|
|
|
|
|
.Take(pageSize).ToList(); |
|
|
|
|
|
|
|
|
|
|
|
var model = new PaginatedItemsViewModel<CampaignDTO>( |
|
|
|
|
|
pageIndex, pageSize, totalItems, campaignDtoList); |
|
|
|
|
|
|
|
|
|
|
|
return Ok(model); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|