Last active
February 23, 2020 17:16
ASP.NET Core ile Event Sourcing 01 - Store - TasksController.cs
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
namespace EventSourcingTaskApp.Controllers | |
{ | |
using EventSourcingTaskApp.Core; | |
using EventSourcingTaskApp.Infrastructure; | |
using Microsoft.AspNetCore.Mvc; | |
using System; | |
using System.Threading.Tasks; | |
[Route("api/tasks/{id}")] | |
[ApiController] | |
[Consumes("application/x-www-form-urlencoded")] | |
public class TasksController : ControllerBase | |
{ | |
private readonly AggregateRepository _aggregateRepository; | |
public TasksController(AggregateRepository aggregateRepository) | |
{ | |
_aggregateRepository = aggregateRepository; | |
} | |
[HttpPost, Route("create")] | |
public async Task<IActionResult> Create(Guid id, [FromForm] string title) | |
{ | |
var aggregate = await _aggregateRepository.LoadAsync<Core.Task>(id); | |
aggregate.Create(id, title, "Ahmet KÜÇÜKOĞLU"); | |
await _aggregateRepository.SaveAsync(aggregate); | |
return Ok(); | |
} | |
[HttpPatch, Route("assign")] | |
public async Task<IActionResult> Assign(Guid id, [FromForm] string assignedTo) | |
{ | |
var aggregate = await _aggregateRepository.LoadAsync<Core.Task>(id); | |
aggregate.Assign(assignedTo, "Ahmet KÜÇÜKOĞLU"); | |
await _aggregateRepository.SaveAsync(aggregate); | |
return Ok(); | |
} | |
[HttpPatch, Route("move")] | |
public async Task<IActionResult> Move(Guid id, [FromForm] BoardSections section) | |
{ | |
var aggregate = await _aggregateRepository.LoadAsync<Core.Task>(id); | |
aggregate.Move(section, "Ahmet KÜÇÜKOĞLU"); | |
await _aggregateRepository.SaveAsync(aggregate); | |
return Ok(); | |
} | |
[HttpPatch, Route("complete")] | |
public async Task<IActionResult> Complete(Guid id) | |
{ | |
var aggregate = await _aggregateRepository.LoadAsync<Core.Task>(id); | |
aggregate.Complete("Ahmet KÜÇÜKOĞLU"); | |
await _aggregateRepository.SaveAsync(aggregate); | |
return Ok(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment