mirror of
https://github.com/Sea-Haven-Industries/shoc-backend.git
synced 2026-09-30 22:23:12 +00:00
44 lines
1.4 KiB
C#
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");
|
|
}
|
|
}
|
|
}
|