mirror of
https://github.com/Sea-Haven-Industries/shoc-backend.git
synced 2026-09-30 08:23:12 +00:00
71 lines
2.6 KiB
C#
71 lines
2.6 KiB
C#
using FluentValidation;
|
|
using SeaHaven.Services.DTOs;
|
|
using Data.SeaHavenIndustries.Enums;
|
|
|
|
namespace SeaHaven.Services.Validation
|
|
{
|
|
public interface ICreateWorkOrderValidation : IValidator<CreateWorkOrderDTO>
|
|
{
|
|
}
|
|
|
|
public class CreateWorkOrderValidation : AbstractValidator<CreateWorkOrderDTO>, ICreateWorkOrderValidation
|
|
{
|
|
public CreateWorkOrderValidation()
|
|
{
|
|
RuleFor(x => x.WorkerOrderTitle)
|
|
.NotEmpty().WithMessage("Work order title is required")
|
|
.MaximumLength(200).WithMessage("Title cannot exceed 200 characters");
|
|
|
|
RuleFor(x => x.Description)
|
|
.MaximumLength(2000).WithMessage("Description cannot exceed 2000 characters")
|
|
.When(x => !string.IsNullOrEmpty(x.Description));
|
|
|
|
RuleFor(x => x.LocationId)
|
|
.GreaterThan(0).WithMessage("Valid location must be selected")
|
|
.When(x => x.LocationId.HasValue);
|
|
|
|
RuleFor(x => x.Priority)
|
|
.IsInEnum().WithMessage("Invalid priority value")
|
|
.When(x => x.Priority.HasValue);
|
|
|
|
RuleFor(x => x.Status)
|
|
.IsInEnum().WithMessage("Invalid status value")
|
|
.When(x => x.Status.HasValue);
|
|
|
|
RuleFor(x => x.DueDate)
|
|
.GreaterThan(DateTime.Now.AddDays(-1))
|
|
.When(x => x.DueDate.HasValue)
|
|
.WithMessage("Due date cannot be in the past");
|
|
}
|
|
}
|
|
|
|
public interface IUpdateWorkOrderValidation : IValidator<UpdateWorkOrderDTO>
|
|
{
|
|
}
|
|
|
|
public class UpdateWorkOrderValidation : AbstractValidator<UpdateWorkOrderDTO>, IUpdateWorkOrderValidation
|
|
{
|
|
public UpdateWorkOrderValidation()
|
|
{
|
|
RuleFor(x => x.WorkerOrderTitle)
|
|
.MaximumLength(200).WithMessage("Title cannot exceed 200 characters")
|
|
.When(x => !string.IsNullOrEmpty(x.WorkerOrderTitle));
|
|
|
|
RuleFor(x => x.Description)
|
|
.MaximumLength(2000).WithMessage("Description cannot exceed 2000 characters")
|
|
.When(x => !string.IsNullOrEmpty(x.Description));
|
|
|
|
RuleFor(x => x.LocationId)
|
|
.GreaterThan(0).WithMessage("Valid location must be selected")
|
|
.When(x => x.LocationId.HasValue);
|
|
|
|
RuleFor(x => x.Priority)
|
|
.IsInEnum().WithMessage("Invalid priority value")
|
|
.When(x => x.Priority.HasValue);
|
|
|
|
RuleFor(x => x.Status)
|
|
.IsInEnum().WithMessage("Invalid status value")
|
|
.When(x => x.Status.HasValue);
|
|
}
|
|
}
|
|
}
|