Check when the user doesn't have any location in database

This commit is contained in:
Christian Arenas 2017-06-19 00:34:00 +02:00
parent db4403b75c
commit ed97efaf61
3 changed files with 21 additions and 26 deletions

View File

@ -7,12 +7,12 @@
using AspNetCore.Mvc; using AspNetCore.Mvc;
using Infrastructure; using Infrastructure;
using System.Threading.Tasks; using System.Threading.Tasks;
using Catalog.API.ViewModel;
using Model; using Model;
using EntityFrameworkCore; using EntityFrameworkCore;
using Dto; using Dto;
using AspNetCore.Authorization; using AspNetCore.Authorization;
using Extensions.Options; using Extensions.Options;
using Microsoft.eShopOnContainers.Services.Marketing.API.ViewModel;
[Route("api/v1/[controller]")] [Route("api/v1/[controller]")]
[Authorize] [Authorize]
@ -129,29 +129,27 @@
{ {
var marketingData = await _marketingDataRepository.GetAsync(userId.ToString()); var marketingData = await _marketingDataRepository.GetAsync(userId.ToString());
if (marketingData is null)
{
return NotFound();
}
var campaignDtoList = new List<CampaignDTO>(); var campaignDtoList = new List<CampaignDTO>();
//Get User Location Campaign if (marketingData != null)
foreach (var userLocation in marketingData.Locations)
{ {
var userCampaignList = await _context.Rules //Get User Location Campaign
.OfType<UserLocationRule>() foreach (var userLocation in marketingData.Locations)
.Include(c => c.Campaign)
.Where(c => c.Campaign.From <= DateTime.Now
&& c.Campaign.To >= DateTime.Now
&& c.LocationId == userLocation.LocationId)
.Select(c => c.Campaign)
.ToListAsync();
if (userCampaignList != null && userCampaignList.Any())
{ {
var userCampaignDtoList = MapCampaignModelListToDtoList(userCampaignList); var userCampaignList = await _context.Rules
campaignDtoList.AddRange(userCampaignDtoList); .OfType<UserLocationRule>()
.Include(c => c.Campaign)
.Where(c => c.Campaign.From <= DateTime.Now
&& c.Campaign.To >= DateTime.Now
&& c.LocationId == userLocation.LocationId)
.Select(c => c.Campaign)
.ToListAsync();
if (userCampaignList != null && userCampaignList.Any())
{
var userCampaignDtoList = MapCampaignModelListToDtoList(userCampaignList);
campaignDtoList.AddRange(userCampaignDtoList);
}
} }
} }

View File

@ -1,8 +1,7 @@
namespace Microsoft.eShopOnContainers.Services.Catalog.API.ViewModel namespace Microsoft.eShopOnContainers.Services.Marketing.API.ViewModel
{ {
using System.Collections.Generic; using System.Collections.Generic;
public class PaginatedItemsViewModel<TEntity> where TEntity : class public class PaginatedItemsViewModel<TEntity> where TEntity : class
{ {
public int PageIndex { get; private set; } public int PageIndex { get; private set; }

View File

@ -1,6 +1,3 @@
using Microsoft.EntityFrameworkCore.Query.Internal;
using WebMVC.ViewModels;
namespace Microsoft.eShopOnContainers.WebMVC.Controllers namespace Microsoft.eShopOnContainers.WebMVC.Controllers
{ {
using AspNetCore.Authorization; using AspNetCore.Authorization;
@ -10,6 +7,7 @@ namespace Microsoft.eShopOnContainers.WebMVC.Controllers
using System.Threading.Tasks; using System.Threading.Tasks;
using System; using System;
using ViewModels.Pagination; using ViewModels.Pagination;
using global::WebMVC.ViewModels;
[Authorize] [Authorize]
public class CampaignsController : Controller public class CampaignsController : Controller