26 lines
675 B
C#
26 lines
675 B
C#
using Hutopy.Application.Common.Interfaces;
|
|
using Hutopy.Domain.Entities;
|
|
|
|
namespace Hutopy.Application.TodoLists.Commands.CreateTodoList;
|
|
|
|
public record CreateTodoListCommand : IRequest<int>
|
|
{
|
|
public string? Title { get; init; }
|
|
}
|
|
|
|
public class CreateTodoListCommandHandler(
|
|
IApplicationDbContext context)
|
|
: IRequestHandler<CreateTodoListCommand, int>
|
|
{
|
|
public async Task<int> Handle(CreateTodoListCommand request, CancellationToken cancellationToken)
|
|
{
|
|
var entity = new TodoList { Title = request.Title };
|
|
|
|
context.TodoLists.Add(entity);
|
|
|
|
await context.SaveChangesAsync(cancellationToken);
|
|
|
|
return entity.Id;
|
|
}
|
|
}
|