forked from EduardoPires/EquinoxProject
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added project with WebAPI without Mvc
- Loading branch information
Thiago Lunardi
committed
Aug 3, 2017
1 parent
bb8c2c1
commit 293580a
Showing
10 changed files
with
1,132 additions
and
1 deletion.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using Equinox.Domain.Core.Notifications; | ||
using Microsoft.AspNetCore.Mvc; | ||
using System.Collections.Generic; | ||
|
||
namespace Equinox.WebApi.Controllers | ||
{ | ||
public abstract class ApiController : ControllerBase | ||
{ | ||
private readonly IDomainNotificationHandler<DomainNotification> _notifications; | ||
|
||
public ApiController(IDomainNotificationHandler<DomainNotification> notifications) | ||
{ | ||
_notifications = notifications; | ||
} | ||
|
||
protected IEnumerable<DomainNotification> Notifications => _notifications.GetNotifications(); | ||
|
||
protected bool IsValidOperation() | ||
{ | ||
return (!_notifications.HasNotifications()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
using System; | ||
using Equinox.Application.Interfaces; | ||
using Equinox.Application.ViewModels; | ||
using Equinox.Domain.Core.Notifications; | ||
using Microsoft.AspNetCore.Authorization; | ||
using Microsoft.AspNetCore.Mvc; | ||
|
||
namespace Equinox.WebApi.Controllers | ||
{ | ||
[Authorize] | ||
public class CustomerController : ApiController | ||
{ | ||
private readonly ICustomerAppService _customerAppService; | ||
|
||
public CustomerController(ICustomerAppService customerAppService, IDomainNotificationHandler<DomainNotification> notifications) : base(notifications) | ||
{ | ||
_customerAppService = customerAppService; | ||
} | ||
|
||
[HttpGet] | ||
[AllowAnonymous] | ||
[Route("customer-management/list-all")] | ||
public IActionResult Index() | ||
{ | ||
return Ok(_customerAppService.GetAll()); | ||
} | ||
|
||
[HttpGet] | ||
[AllowAnonymous] | ||
[Route("customer-management/customer-details/{id:guid}")] | ||
public IActionResult Details(Guid? id) | ||
{ | ||
if (id == null) | ||
{ | ||
return BadRequest(); | ||
} | ||
|
||
var customerViewModel = _customerAppService.GetById(id.Value); | ||
|
||
if (customerViewModel == null) | ||
{ | ||
return NotFound(); | ||
} | ||
|
||
return Ok(customerViewModel); | ||
} | ||
|
||
[HttpPost] | ||
[Authorize(Policy = "CanWriteCustomerData")] | ||
[Route("customer-management/register-new")] | ||
[ValidateAntiForgeryToken] | ||
public IActionResult Create(CustomerViewModel customerViewModel) | ||
{ | ||
if (!ModelState.IsValid) return BadRequest(customerViewModel); | ||
_customerAppService.Register(customerViewModel); | ||
|
||
if (IsValidOperation()) | ||
Ok(); | ||
|
||
return BadRequest(Notifications); | ||
} | ||
|
||
[HttpGet] | ||
[Authorize(Policy = "CanWriteCustomerData")] | ||
[Route("customer-management/edit-customer/{id:guid}")] | ||
public IActionResult Edit(Guid? id) | ||
{ | ||
if (id == null) | ||
{ | ||
return NotFound(); | ||
} | ||
|
||
var customerViewModel = _customerAppService.GetById(id.Value); | ||
|
||
if (customerViewModel == null) | ||
{ | ||
return NotFound(); | ||
} | ||
|
||
return Ok(customerViewModel); | ||
} | ||
|
||
[HttpPut] | ||
[Authorize(Policy = "CanWriteCustomerData")] | ||
[Route("customer-management/edit-customer/{id:guid}")] | ||
[ValidateAntiForgeryToken] | ||
public IActionResult Edit(CustomerViewModel customerViewModel) | ||
{ | ||
if (!ModelState.IsValid) return BadRequest(customerViewModel); | ||
|
||
_customerAppService.Update(customerViewModel); | ||
|
||
if (IsValidOperation()) | ||
Ok(); | ||
|
||
return BadRequest(Notifications); | ||
} | ||
|
||
[HttpGet] | ||
[Authorize(Policy = "CanRemoveCustomerData")] | ||
[Route("customer-management/remove-customer/{id:guid}")] | ||
public IActionResult Delete(Guid? id) | ||
{ | ||
if (id == null) | ||
{ | ||
return BadRequest(); | ||
} | ||
|
||
var customerViewModel = _customerAppService.GetById(id.Value); | ||
|
||
if (customerViewModel == null) | ||
{ | ||
return NotFound(); | ||
} | ||
|
||
return Ok(customerViewModel); | ||
} | ||
|
||
[HttpPost, ActionName("Delete")] | ||
[Authorize(Policy = "CanRemoveCustomerData")] | ||
[Route("customer-management/remove-customer/{id:guid}")] | ||
[ValidateAntiForgeryToken] | ||
public IActionResult DeleteConfirmed(Guid id) | ||
{ | ||
_customerAppService.Remove(id); | ||
|
||
if (!IsValidOperation()) return BadRequest(Notifications); | ||
|
||
return DeleteConfirmed(id); | ||
} | ||
|
||
[AllowAnonymous] | ||
[Route("customer-management/customer-history/{id:guid}")] | ||
public IActionResult History(Guid id) | ||
{ | ||
var customerHistoryData = _customerAppService.GetAllHistory(id); | ||
return Ok(customerHistoryData); | ||
} | ||
} | ||
} |
Oops, something went wrong.