First commit. Include junk from template to remove
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
using Hutopy.Application.Common.Interfaces;
|
||||
|
||||
namespace Hutopy.Application.TodoLists.Commands.CreateTodoList;
|
||||
|
||||
public class CreateTodoListCommandValidator : AbstractValidator<CreateTodoListCommand>
|
||||
{
|
||||
private readonly IApplicationDbContext _context;
|
||||
|
||||
public CreateTodoListCommandValidator(IApplicationDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
|
||||
RuleFor(v => v.Title)
|
||||
.NotEmpty()
|
||||
.MaximumLength(200)
|
||||
.MustAsync(BeUniqueTitle)
|
||||
.WithMessage("'{PropertyName}' must be unique.")
|
||||
.WithErrorCode("Unique");
|
||||
}
|
||||
|
||||
public async Task<bool> BeUniqueTitle(string title, CancellationToken cancellationToken)
|
||||
{
|
||||
return await _context.TodoLists
|
||||
.AllAsync(l => l.Title != title, cancellationToken);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user