Edit campaigns controller
This commit is contained in:
parent
f62131f832
commit
31b1c4a197
@ -8,10 +8,9 @@
|
|||||||
using Microsoft.eShopOnContainers.Services.Marketing.API.Dto;
|
using Microsoft.eShopOnContainers.Services.Marketing.API.Dto;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using System.Linq;
|
|
||||||
|
|
||||||
[Route("api/v1/[controller]")]
|
[Route("api/v1/[controller]")]
|
||||||
[Authorize]
|
//[Authorize]
|
||||||
public class CampaignsController : Controller
|
public class CampaignsController : Controller
|
||||||
{
|
{
|
||||||
private readonly MarketingContext _context;
|
private readonly MarketingContext _context;
|
||||||
@ -51,14 +50,14 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public async Task<IActionResult> CreateCampaign([FromBody] CampaignDTO campaign)
|
public async Task<IActionResult> CreateCampaign([FromBody] CampaignDTO campaignDto)
|
||||||
{
|
{
|
||||||
if (campaign is null)
|
if (campaignDto is null)
|
||||||
{
|
{
|
||||||
return BadRequest();
|
return BadRequest();
|
||||||
}
|
}
|
||||||
|
|
||||||
var campaingToCreate = MapCampaignDtoToModel(campaign);
|
var campaingToCreate = MapCampaignDtoToModel(campaignDto);
|
||||||
|
|
||||||
await _context.Campaigns.AddAsync(campaingToCreate);
|
await _context.Campaigns.AddAsync(campaingToCreate);
|
||||||
await _context.SaveChangesAsync();
|
await _context.SaveChangesAsync();
|
||||||
@ -67,9 +66,9 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpPut("{id:int}")]
|
[HttpPut("{id:int}")]
|
||||||
public async Task<IActionResult> UpdateCampaign(int id, [FromBody]CampaignDTO campaign)
|
public async Task<IActionResult> UpdateCampaign(int id, [FromBody]CampaignDTO campaignDto)
|
||||||
{
|
{
|
||||||
if (id < 1 || campaign is null)
|
if (id < 1 || campaignDto is null)
|
||||||
{
|
{
|
||||||
return BadRequest();
|
return BadRequest();
|
||||||
}
|
}
|
||||||
@ -80,9 +79,10 @@
|
|||||||
return NotFound();
|
return NotFound();
|
||||||
}
|
}
|
||||||
|
|
||||||
campaignToUpdate.Description = campaign.Description;
|
campaignToUpdate.Description = campaignDto.Description;
|
||||||
campaignToUpdate.From = campaign.From;
|
campaignToUpdate.From = campaignDto.From;
|
||||||
campaignToUpdate.To = campaign.To;
|
campaignToUpdate.To = campaignDto.To;
|
||||||
|
campaignToUpdate.Url = campaignDto.Url;
|
||||||
|
|
||||||
await _context.SaveChangesAsync();
|
await _context.SaveChangesAsync();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user