Skip to content

Commit

Permalink
Added project with WebAPI without Mvc
Browse files Browse the repository at this point in the history
  • Loading branch information
Thiago Lunardi committed Aug 3, 2017
1 parent bb8c2c1 commit 293580a
Show file tree
Hide file tree
Showing 10 changed files with 1,132 additions and 1 deletion.
426 changes: 426 additions & 0 deletions Equinox.WebApi/Controllers/AccountController.cs

Large diffs are not rendered by default.

23 changes: 23 additions & 0 deletions Equinox.WebApi/Controllers/ApiController.cs
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());
}
}
}
140 changes: 140 additions & 0 deletions Equinox.WebApi/Controllers/CustomerController.cs
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);
}
}
}
Loading

0 comments on commit 293580a

Please sign in to comment.