NTP_V2/src/NTP.Application/Grains/Orders/OrdersValidators.cs

74 lines
3.7 KiB
C#

using FluentValidation;
using NTP.Domain.Grains.Orders;
namespace NTP.Application.Grains.Orders;
public sealed class CreateTenderOrderValidator : AbstractValidator<CreateTenderOrderRequest>
{
public CreateTenderOrderValidator()
{
RuleFor(x => x.CargoType).GreaterThan(0).WithMessage("نمط الحمولة مطلوب");
RuleFor(x => x.Location).GreaterThan(0).WithMessage("موقع التحميل مطلوب");
RuleFor(x => x.Destination).GreaterThan(0).WithMessage("الوجهه مطلوبة");
RuleFor(x => x.OrderDate).NotEmpty().WithMessage("تاريخ الطلبية مطلوب");
RuleFor(x => x.Shift).InclusiveBetween(1, 3).When(x => x.Shift.HasValue).WithMessage("الفترة غير صحيحة");
RuleFor(x => x.Quantity)
.Must(TenderOrderRules.IsQuantityValid).WithMessage("عدد السيارات يجب ان يكون بين 1 - 200");
RuleFor(x => x.Type)
.NotEmpty().WithMessage("شركات \\ أفراد مطلوب")
.When(x => TenderOrderRules.IsTypeRequired(x.CargoType));
RuleFor(x => x.Type)
.Must(TenderOrderRules.IsValidType).WithMessage("قيمة شركات \\ أفراد غير صحيحة")
.When(x => !string.IsNullOrWhiteSpace(x.Type));
}
}
public sealed class SetQuotaValidator : AbstractValidator<SetQuotaRequest>
{
public SetQuotaValidator()
{
RuleFor(x => x.DestinationId).GreaterThan(0);
RuleFor(x => x.QuotaDate).NotEmpty();
RuleFor(x => x.Quota).GreaterThanOrEqualTo(0).LessThanOrEqualTo(1_000_000);
}
}
public sealed class AddBillingValidator : AbstractValidator<AddBillingRequest>
{
public AddBillingValidator()
{
RuleFor(x => x.Pn).GreaterThan(0).WithMessage("رقم الارسالية مطلوب");
RuleFor(x => x.Scac).GreaterThan(0).WithMessage("اسم الشركة مطلوب");
RuleFor(x => x.InvoiceNumber).GreaterThan(0).WithMessage("رقم المطالبة مطلوب");
// GRAINS_BILLING.SERIALNO is numeric, so the document number must be digits
RuleFor(x => x.SerialNo).NotEmpty().Matches(@"^[0-9]{1,12}$").WithMessage("رقم المستند مطلوب");
RuleFor(x => x.LoadDate).NotEmpty().WithMessage("تاريخ التحميل مطلوب");
RuleFor(x => x.DischargeDate).NotEmpty().WithMessage("تاريخ التفريغ مطلوب");
RuleFor(x => x.Destination).GreaterThan(0).WithMessage("الى مطلوب");
RuleFor(x => x.CargoType).GreaterThan(0).WithMessage("نوع المادة مطلوب");
RuleFor(x => x.Tn).NotEmpty().MaximumLength(20).WithMessage("رقم السيارة مطلوب");
RuleFor(x => x.DemurrageFine).GreaterThanOrEqualTo(0).WithMessage("غرامة التاخير غير صحيحة");
RuleFor(x => x.OtherFine).GreaterThanOrEqualTo(0).WithMessage("غرامات أخرى غير صحيحة");
}
}
public sealed class SaveWeightsValidator : AbstractValidator<SaveWeightsRequest>
{
public SaveWeightsValidator()
{
RuleFor(x => x.Pn).GreaterThan(0).WithMessage("رقم الارسالية مطلوب");
RuleFor(x => x.EmptyWeight).NotEmpty().WithMessage("الوزن الفارغ مطلوب");
RuleFor(x => x.GrossWeight).NotEmpty().WithMessage("الوزن القائم مطلوب");
RuleFor(x => x.DocumentNumber).NotEmpty().MaximumLength(12).WithMessage("رقم مستند الشحن مطلوب");
}
}
public sealed class SaveCompanyDestinationsValidator : AbstractValidator<SaveCompanyDestinationsRequest>
{
public SaveCompanyDestinationsValidator()
{
RuleFor(x => x.LocationIds).NotNull();
RuleForEach(x => x.LocationIds).GreaterThan(0);
}
}