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

78 lines
2.8 KiB
C#

using FluentValidation;
using SeaHaven.Services.DTOs;
using Data.SeaHavenIndustries.Enums;
namespace SeaHaven.Services.Validation
{
public interface ICreateFollowUpValidation : IValidator<CreateFollowUpDTO>
{
}
public class CreateFollowUpValidation : AbstractValidator<CreateFollowUpDTO>, ICreateFollowUpValidation
{
public CreateFollowUpValidation()
{
RuleFor(x => x.Reason)
.NotEmpty().WithMessage("Reason is required")
.MaximumLength(500).WithMessage("Reason cannot exceed 500 characters");
RuleFor(x => x.Status)
.NotEmpty().WithMessage("Status is required");
RuleFor(x => x.ScheduleDate)
.GreaterThan(DateTime.Now.AddDays(-1))
.WithMessage("Schedule date cannot be in the past");
RuleFor(x => x.EmployeeId)
.GreaterThan(0).WithMessage("Valid employee must be selected")
.When(x => x.EmployeeId.HasValue);
RuleFor(x => x.WorkOrderId)
.GreaterThan(0).WithMessage("Valid work order must be selected")
.When(x => x.WorkOrderId.HasValue);
RuleFor(x => x.AccountId)
.GreaterThan(0).WithMessage("Valid account must be selected")
.When(x => x.AccountId.HasValue);
RuleFor(x => x.LocationId)
.GreaterThan(0).WithMessage("Valid location must be selected")
.When(x => x.LocationId.HasValue);
}
}
public interface IUpdateFollowUpValidation : IValidator<UpdateFollowUpDTO>
{
}
public class UpdateFollowUpValidation : AbstractValidator<UpdateFollowUpDTO>, IUpdateFollowUpValidation
{
public UpdateFollowUpValidation()
{
RuleFor(x => x.Reason)
.MaximumLength(500).WithMessage("Reason cannot exceed 500 characters")
.When(x => !string.IsNullOrEmpty(x.Reason));
RuleFor(x => x.ScheduleDate)
.GreaterThan(DateTime.Now.AddDays(-1))
.When(x => x.ScheduleDate.HasValue)
.WithMessage("Schedule date cannot be in the past");
RuleFor(x => x.EmployeeId)
.GreaterThan(0).WithMessage("Valid employee must be selected")
.When(x => x.EmployeeId.HasValue);
RuleFor(x => x.WorkOrderId)
.GreaterThan(0).WithMessage("Valid work order must be selected")
.When(x => x.WorkOrderId.HasValue);
RuleFor(x => x.AccountId)
.GreaterThan(0).WithMessage("Valid account must be selected")
.When(x => x.AccountId.HasValue);
RuleFor(x => x.LocationId)
.GreaterThan(0).WithMessage("Valid location must be selected")
.When(x => x.LocationId.HasValue);
}
}
}