mirror of
https://github.com/Sea-Haven-Industries/shoc-backend.git
synced 2026-09-30 13:03:12 +00:00
62 lines
2.2 KiB
C#
62 lines
2.2 KiB
C#
using FluentValidation;
|
|
using SeaHaven.Services.DTOs;
|
|
|
|
namespace SeaHaven.Services.Validation
|
|
{
|
|
public interface ICreatePMScheduleValidation : IValidator<CreatePMScheduleDTO>
|
|
{
|
|
}
|
|
|
|
public class CreatePMScheduleValidation : AbstractValidator<CreatePMScheduleDTO>, ICreatePMScheduleValidation
|
|
{
|
|
public CreatePMScheduleValidation()
|
|
{
|
|
RuleFor(x => x.Name)
|
|
.NotEmpty().WithMessage("PM Schedule name is required")
|
|
.MaximumLength(200).WithMessage("Name cannot exceed 200 characters");
|
|
|
|
RuleFor(x => x.Frequency)
|
|
.NotEmpty().WithMessage("Frequency is required");
|
|
|
|
RuleFor(x => x.StartDate)
|
|
.NotEmpty().WithMessage("Start date is required")
|
|
.LessThanOrEqualTo(DateTime.Now.AddYears(1))
|
|
.WithMessage("Start date cannot be more than 1 year in the future");
|
|
|
|
RuleFor(x => x.AssetId)
|
|
.GreaterThan(0).WithMessage("Valid asset must be selected")
|
|
.When(x => x.AssetId.HasValue);
|
|
|
|
RuleFor(x => x.LocationId)
|
|
.GreaterThan(0).WithMessage("Valid location must be selected")
|
|
.When(x => x.LocationId.HasValue);
|
|
}
|
|
}
|
|
|
|
public interface IUpdatePMScheduleValidation : IValidator<UpdatePMScheduleDTO>
|
|
{
|
|
}
|
|
|
|
public class UpdatePMScheduleValidation : AbstractValidator<UpdatePMScheduleDTO>, IUpdatePMScheduleValidation
|
|
{
|
|
public UpdatePMScheduleValidation()
|
|
{
|
|
RuleFor(x => x.Name)
|
|
.MaximumLength(200).WithMessage("Name cannot exceed 200 characters")
|
|
.When(x => !string.IsNullOrEmpty(x.Name));
|
|
|
|
RuleFor(x => x.StartDate)
|
|
.LessThanOrEqualTo(DateTime.Now.AddYears(1))
|
|
.When(x => x.StartDate.HasValue)
|
|
.WithMessage("Start date cannot be more than 1 year in the future");
|
|
|
|
RuleFor(x => x.AssetId)
|
|
.GreaterThan(0).WithMessage("Valid asset must be selected")
|
|
.When(x => x.AssetId.HasValue);
|
|
|
|
RuleFor(x => x.LocationId)
|
|
.GreaterThan(0).WithMessage("Valid location must be selected")
|
|
.When(x => x.LocationId.HasValue);
|
|
}
|
|
}
|
|
}
|