mirror of
https://github.com/Sea-Haven-Industries/proposal-system.git
synced 2026-10-05 15:21:59 +00:00
39 lines
1.3 KiB
C#
39 lines
1.3 KiB
C#
|
|
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);
|
||
|
|
});
|
||
|
|
}
|
||
|
|
}
|