proposal-system/api/src/ProposalSystem.Application/Validators/BulkUpdateLineItemsValidator.cs

39 lines
1.3 KiB
C#
Raw Normal View History

using FluentValidation;
using ProposalSystem.Application.DTOs;
namespace ProposalSystem.Application.Validators;
public class BulkUpdateLineItemsValidator : AbstractValidator<BulkUpdateLineItemsRequest>
{
public BulkUpdateLineItemsValidator()
{
RuleFor(x => x.LineItems).NotNull();
RuleForEach(x => x.LineItems).ChildRules(entry =>
{
entry.RuleFor(x => x.Description)
.NotEmpty().WithMessage("Description is required")
.MaximumLength(1000);
entry.RuleFor(x => x.Quantity)
.GreaterThan(0).WithMessage("Quantity must be positive");
entry.RuleFor(x => x.Unit)
.NotEmpty().WithMessage("Unit is required")
.MaximumLength(50);
entry.RuleFor(x => x.TotalPrice)
.GreaterThanOrEqualTo(0).WithMessage("Total price cannot be negative");
entry.RuleFor(x => x.UnitPrice)
.GreaterThanOrEqualTo(0)
.When(x => x.UnitPrice.HasValue)
.WithMessage("Unit price cannot be negative");
entry.RuleFor(x => x.PricingMode).IsInEnum();
entry.RuleFor(x => x.Source).IsInEnum();
entry.RuleFor(x => x.SortOrder).GreaterThanOrEqualTo(0);
});
}
}