classlib/ExpenseTracker.Application/Transactions/Commands/Update/UpdateTransactionCommandValidator.cs
2024-08-07 21:12:02 +03:00

30 lines
862 B
C#

using FluentValidation;
using ExpenseTracker.Domain.Enums;
namespace ExpenseTracker.Application.Transactions.Commands.Update;
public class UpdateTransactionCommandValidator : AbstractValidator<UpdateTransactionCommand>
{
public UpdateTransactionCommandValidator()
{
RuleFor(e => e.Id)
.NotEmpty();
RuleFor(e => e.Amount);
RuleFor(e => e.Category)
.Must(c =>
Category.Enumerations.Any(e => e.Value.Equals(Category.FromName(c))) ||
c == null)
.WithMessage(c => $"'{nameof(c.Category)}' must be one of the following: '{String.Join("', ", Category.Enumerations.Values.Select(v => v.Name))}'.");
RuleFor(e => e.Time);
RuleFor(e => e.Description)
.Length(0, 256);
RuleFor(e => e.AccountId)
.NotEmpty();
}
}