using Hutopy.Application.Common.Interfaces; using Hutopy.Domain.Entities; using Hutopy.Domain.Events; namespace Hutopy.Application.TodoItems.Commands.CreateTodoItem; public record CreateTodoItemCommand : IRequest { public int ListId { get; init; } public string? Title { get; init; } } public class CreateTodoItemCommandHandler( IApplicationDbContext context) : IRequestHandler { public async Task 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; } }