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

57 lines
2 KiB
C#

using FluentValidation;
using SeaHaven.Services.DTOs;
namespace SeaHaven.Services.Validation
{
public interface ICreateAccountValidation : IValidator<CreateAccountDTO>
{
}
public class CreateAccountValidation : AbstractValidator<CreateAccountDTO>, ICreateAccountValidation
{
public CreateAccountValidation()
{
RuleFor(x => x.Name)
.NotEmpty().WithMessage("Account name is required")
.MaximumLength(200).WithMessage("Account name cannot exceed 200 characters");
RuleFor(x => x.Email)
.EmailAddress().WithMessage("Invalid email address")
.When(x => !string.IsNullOrEmpty(x.Email));
RuleFor(x => x.Phone)
.MaximumLength(20).WithMessage("Phone number cannot exceed 20 characters")
.When(x => !string.IsNullOrEmpty(x.Phone));
RuleFor(x => x.Website)
.MaximumLength(200).WithMessage("Website cannot exceed 200 characters")
.When(x => !string.IsNullOrEmpty(x.Website));
}
}
public interface IUpdateAccountValidation : IValidator<UpdateAccountDTO>
{
}
public class UpdateAccountValidation : AbstractValidator<UpdateAccountDTO>, IUpdateAccountValidation
{
public UpdateAccountValidation()
{
RuleFor(x => x.Name)
.MaximumLength(200).WithMessage("Account name cannot exceed 200 characters")
.When(x => !string.IsNullOrEmpty(x.Name));
RuleFor(x => x.Email)
.EmailAddress().WithMessage("Invalid email address")
.When(x => !string.IsNullOrEmpty(x.Email));
RuleFor(x => x.Phone)
.MaximumLength(20).WithMessage("Phone number cannot exceed 20 characters")
.When(x => !string.IsNullOrEmpty(x.Phone));
RuleFor(x => x.Website)
.MaximumLength(200).WithMessage("Website cannot exceed 200 characters")
.When(x => !string.IsNullOrEmpty(x.Website));
}
}
}