Check when list is null and campaign details doesn't exist
This commit is contained in:
parent
ff790afe56
commit
278083ae8e
@ -2,9 +2,9 @@ namespace Microsoft.eShopOnContainers.WebMVC.Controllers
|
|||||||
{
|
{
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.eShopOnContainers.WebMVC.Models;
|
||||||
using Microsoft.eShopOnContainers.WebMVC.Services;
|
using Microsoft.eShopOnContainers.WebMVC.Services;
|
||||||
using Microsoft.eShopOnContainers.WebMVC.ViewModels;
|
using Microsoft.eShopOnContainers.WebMVC.ViewModels;
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
@ -18,7 +18,14 @@ namespace Microsoft.eShopOnContainers.WebMVC.Controllers
|
|||||||
|
|
||||||
public async Task<IActionResult> Index()
|
public async Task<IActionResult> Index()
|
||||||
{
|
{
|
||||||
var campaignList = await _campaignService.GetCampaigns();
|
var campaignDtoList = await _campaignService.GetCampaigns();
|
||||||
|
|
||||||
|
if(campaignDtoList is null)
|
||||||
|
{
|
||||||
|
return View();
|
||||||
|
}
|
||||||
|
|
||||||
|
var campaignList = MapCampaignModelListToDtoList(campaignDtoList);
|
||||||
|
|
||||||
return View(campaignList);
|
return View(campaignList);
|
||||||
}
|
}
|
||||||
@ -27,6 +34,11 @@ namespace Microsoft.eShopOnContainers.WebMVC.Controllers
|
|||||||
{
|
{
|
||||||
var campaignDto = await _campaignService.GetCampaignById(id);
|
var campaignDto = await _campaignService.GetCampaignById(id);
|
||||||
|
|
||||||
|
if (campaignDto is null)
|
||||||
|
{
|
||||||
|
return NotFound();
|
||||||
|
}
|
||||||
|
|
||||||
var campaign = new Campaign
|
var campaign = new Campaign
|
||||||
{
|
{
|
||||||
Id = campaignDto.Id,
|
Id = campaignDto.Id,
|
||||||
@ -39,5 +51,30 @@ namespace Microsoft.eShopOnContainers.WebMVC.Controllers
|
|||||||
|
|
||||||
return View(campaign);
|
return View(campaign);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<Campaign> MapCampaignModelListToDtoList(IEnumerable<CampaignDTO> campaignDtoList)
|
||||||
|
{
|
||||||
|
var campaignList = new List<Campaign>();
|
||||||
|
|
||||||
|
foreach(var campaignDto in campaignDtoList)
|
||||||
|
{
|
||||||
|
campaignList.Add(MapCampaignDtoToModel(campaignDto));
|
||||||
|
}
|
||||||
|
|
||||||
|
return campaignList;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Campaign MapCampaignDtoToModel(CampaignDTO campaign)
|
||||||
|
{
|
||||||
|
return new Campaign
|
||||||
|
{
|
||||||
|
Id = campaign.Id,
|
||||||
|
Name = campaign.Name,
|
||||||
|
Description = campaign.Description,
|
||||||
|
From = campaign.From,
|
||||||
|
To = campaign.To,
|
||||||
|
PictureUri = campaign.PictureUri
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user