First commit. Include junk from template to remove
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
using Hutopy.Application.Common.Interfaces;
|
||||
using Hutopy.Domain.Entities;
|
||||
using Hutopy.Domain.Events;
|
||||
|
||||
namespace Hutopy.Application.TodoItems.Commands.CreateTodoItem;
|
||||
|
||||
public record CreateTodoItemCommand : IRequest<int>
|
||||
{
|
||||
public int ListId { get; init; }
|
||||
|
||||
public string? Title { get; init; }
|
||||
}
|
||||
|
||||
public class CreateTodoItemCommandHandler : IRequestHandler<CreateTodoItemCommand, int>
|
||||
{
|
||||
private readonly IApplicationDbContext _context;
|
||||
|
||||
public CreateTodoItemCommandHandler(IApplicationDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<int> Handle(CreateTodoItemCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var entity = new TodoItem
|
||||
{
|
||||
ListId = request.ListId,
|
||||
Title = request.Title,
|
||||
Done = false
|
||||
};
|
||||
|
||||
entity.AddDomainEvent(new TodoItemCreatedEvent(entity));
|
||||
|
||||
_context.TodoItems.Add(entity);
|
||||
|
||||
await _context.SaveChangesAsync(cancellationToken);
|
||||
|
||||
return entity.Id;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user