Files
social-media/src/Application/TodoLists/Commands/CreateTodoList/CreateTodoList.cs
2024-03-30 20:59:17 -04:00

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;
}
}