19 lines
669 B
C#
19 lines
669 B
C#
using MediatR;
|
|
using SequenceAuth.Example.Domain;
|
|
using SequenceAuth.Example.Infrastructure;
|
|
|
|
namespace SequenceAuth.Example.Features.Todos;
|
|
|
|
public record CreateTodoCommand(Guid UserId, string Title) : IRequest<TodoItem>;
|
|
|
|
public class CreateTodoCommandHandler(AppDbContext dbContext) : IRequestHandler<CreateTodoCommand, TodoItem>
|
|
{
|
|
public async Task<TodoItem> Handle(CreateTodoCommand request, CancellationToken cancellationToken)
|
|
{
|
|
var todo = new TodoItem(Guid.NewGuid(), request.UserId, request.Title, TodoStatus.Pending);
|
|
dbContext.Todos.Add(todo);
|
|
await dbContext.SaveChangesAsync(cancellationToken);
|
|
return todo;
|
|
}
|
|
}
|