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

73 lines
2.8 KiB
C#

using FluentValidation;
using SeaHaven.Services.DTOs;
namespace SeaHaven.Services.Validation
{
public interface ICreateLocationValidation : IValidator<CreateLocationDTO>
{
}
public class CreateLocationValidation : AbstractValidator<CreateLocationDTO>, ICreateLocationValidation
{
public CreateLocationValidation()
{
RuleFor(x => x.LocationName)
.NotEmpty().WithMessage("Location name is required")
.MaximumLength(200).WithMessage("Location name cannot exceed 200 characters");
RuleFor(x => x.Address)
.MaximumLength(500).WithMessage("Address cannot exceed 500 characters")
.When(x => !string.IsNullOrEmpty(x.Address));
RuleFor(x => x.City)
.MaximumLength(100).WithMessage("City cannot exceed 100 characters")
.When(x => !string.IsNullOrEmpty(x.City));
RuleFor(x => x.State)
.MaximumLength(2).WithMessage("State must be 2 characters")
.When(x => !string.IsNullOrEmpty(x.State));
RuleFor(x => x.Zipcode)
.MaximumLength(10).WithMessage("Zipcode cannot exceed 10 characters")
.When(x => !string.IsNullOrEmpty(x.Zipcode));
RuleFor(x => x.AccountId)
.GreaterThan(0).WithMessage("Valid account must be selected")
.When(x => x.AccountId.HasValue);
}
}
public interface IUpdateLocationValidation : IValidator<UpdateLocationDTO>
{
}
public class UpdateLocationValidation : AbstractValidator<UpdateLocationDTO>, IUpdateLocationValidation
{
public UpdateLocationValidation()
{
RuleFor(x => x.LocationName)
.MaximumLength(200).WithMessage("Location name cannot exceed 200 characters")
.When(x => !string.IsNullOrEmpty(x.LocationName));
RuleFor(x => x.Address)
.MaximumLength(500).WithMessage("Address cannot exceed 500 characters")
.When(x => !string.IsNullOrEmpty(x.Address));
RuleFor(x => x.City)
.MaximumLength(100).WithMessage("City cannot exceed 100 characters")
.When(x => !string.IsNullOrEmpty(x.City));
RuleFor(x => x.State)
.MaximumLength(2).WithMessage("State must be 2 characters")
.When(x => !string.IsNullOrEmpty(x.State));
RuleFor(x => x.Zipcode)
.MaximumLength(10).WithMessage("Zipcode cannot exceed 10 characters")
.When(x => !string.IsNullOrEmpty(x.Zipcode));
RuleFor(x => x.AccountId)
.GreaterThan(0).WithMessage("Valid account must be selected")
.When(x => x.AccountId.HasValue);
}
}
}