mirror of
https://github.com/Sea-Haven-Industries/shoc-backend.git
synced 2026-09-30 08:23:12 +00:00
74 lines
2.8 KiB
C#
74 lines
2.8 KiB
C#
|
|
using FluentValidation;
|
||
|
|
using SeaHaven.Services.DTOs;
|
||
|
|
|
||
|
|
namespace SeaHaven.Services.Validation
|
||
|
|
{
|
||
|
|
public interface ICreateContactValidation : IValidator<CreateContactDTO>
|
||
|
|
{
|
||
|
|
}
|
||
|
|
|
||
|
|
public class CreateContactValidation : AbstractValidator<CreateContactDTO>, ICreateContactValidation
|
||
|
|
{
|
||
|
|
public CreateContactValidation()
|
||
|
|
{
|
||
|
|
RuleFor(x => x.FirstName)
|
||
|
|
.NotEmpty().WithMessage("First name is required")
|
||
|
|
.MaximumLength(100).WithMessage("First name cannot exceed 100 characters");
|
||
|
|
|
||
|
|
RuleFor(x => x.LastName)
|
||
|
|
.NotEmpty().WithMessage("Last name is required")
|
||
|
|
.MaximumLength(100).WithMessage("Last name cannot exceed 100 characters");
|
||
|
|
|
||
|
|
RuleFor(x => x.Email)
|
||
|
|
.NotEmpty().WithMessage("Email is required")
|
||
|
|
.EmailAddress().WithMessage("Invalid email address");
|
||
|
|
|
||
|
|
RuleFor(x => x.Phone)
|
||
|
|
.MaximumLength(20).WithMessage("Phone number cannot exceed 20 characters")
|
||
|
|
.When(x => !string.IsNullOrEmpty(x.Phone));
|
||
|
|
|
||
|
|
RuleFor(x => x.Mobile)
|
||
|
|
.MaximumLength(20).WithMessage("Mobile number cannot exceed 20 characters")
|
||
|
|
.When(x => !string.IsNullOrEmpty(x.Mobile));
|
||
|
|
|
||
|
|
RuleFor(x => x.AccountId)
|
||
|
|
.GreaterThan(0).WithMessage("Valid account must be selected")
|
||
|
|
.When(x => x.AccountId.HasValue);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public interface IUpdateContactValidation : IValidator<UpdateContactDTO>
|
||
|
|
{
|
||
|
|
}
|
||
|
|
|
||
|
|
public class UpdateContactValidation : AbstractValidator<UpdateContactDTO>, IUpdateContactValidation
|
||
|
|
{
|
||
|
|
public UpdateContactValidation()
|
||
|
|
{
|
||
|
|
RuleFor(x => x.FirstName)
|
||
|
|
.MaximumLength(100).WithMessage("First name cannot exceed 100 characters")
|
||
|
|
.When(x => !string.IsNullOrEmpty(x.FirstName));
|
||
|
|
|
||
|
|
RuleFor(x => x.LastName)
|
||
|
|
.MaximumLength(100).WithMessage("Last name cannot exceed 100 characters")
|
||
|
|
.When(x => !string.IsNullOrEmpty(x.LastName));
|
||
|
|
|
||
|
|
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.Mobile)
|
||
|
|
.MaximumLength(20).WithMessage("Mobile number cannot exceed 20 characters")
|
||
|
|
.When(x => !string.IsNullOrEmpty(x.Mobile));
|
||
|
|
|
||
|
|
RuleFor(x => x.AccountId)
|
||
|
|
.GreaterThan(0).WithMessage("Valid account must be selected")
|
||
|
|
.When(x => x.AccountId.HasValue);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|