shoc-backend/SeaHaven.Services/Validation/DispatchValidation.cs
2026-05-14 11:00:12 -05:00

44 lines
1.4 KiB
C#

using FluentValidation;
using SeaHaven.Services.DTOs;
using Data.SeaHavenIndustries.Enums;
namespace SeaHaven.Services.Validation
{
public interface ICreateDispatchValidation : IValidator<CreateDispatchDTO>
{
}
public class CreateDispatchValidation : AbstractValidator<CreateDispatchDTO>, ICreateDispatchValidation
{
public CreateDispatchValidation()
{
RuleFor(x => x.VendorId)
.NotEmpty().WithMessage("Vendor is required")
.GreaterThan(0).WithMessage("Valid vendor must be selected");
RuleFor(x => x.ScheduledDate)
.GreaterThan(DateTime.Now.AddDays(-1))
.When(x => x.ScheduledDate.HasValue)
.WithMessage("Scheduled date cannot be in the past");
}
}
public interface IUpdateDispatchValidation : IValidator<UpdateDispatchDTO>
{
}
public class UpdateDispatchValidation : AbstractValidator<UpdateDispatchDTO>, IUpdateDispatchValidation
{
public UpdateDispatchValidation()
{
RuleFor(x => x.VendorId)
.GreaterThan(0).WithMessage("Valid vendor must be selected")
.When(x => x.VendorId.HasValue);
RuleFor(x => x.ScheduledDate)
.GreaterThan(DateTime.Now.AddDays(-1))
.When(x => x.ScheduledDate.HasValue)
.WithMessage("Scheduled date cannot be in the past");
}
}
}