Style: C# 12 Primary constructor
This commit is contained in:
@@ -8,24 +8,17 @@ public record CreateTodoListCommand : IRequest<int>
|
||||
public string? Title { get; init; }
|
||||
}
|
||||
|
||||
public class CreateTodoListCommandHandler : IRequestHandler<CreateTodoListCommand, int>
|
||||
public class CreateTodoListCommandHandler(
|
||||
IApplicationDbContext context)
|
||||
: IRequestHandler<CreateTodoListCommand, int>
|
||||
{
|
||||
private readonly IApplicationDbContext _context;
|
||||
|
||||
public CreateTodoListCommandHandler(IApplicationDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<int> Handle(CreateTodoListCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var entity = new TodoList();
|
||||
var entity = new TodoList { Title = request.Title };
|
||||
|
||||
entity.Title = request.Title;
|
||||
context.TodoLists.Add(entity);
|
||||
|
||||
_context.TodoLists.Add(entity);
|
||||
|
||||
await _context.SaveChangesAsync(cancellationToken);
|
||||
await context.SaveChangesAsync(cancellationToken);
|
||||
|
||||
return entity.Id;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user