mirror of
https://github.com/Sea-Haven-Industries/shoc-backend.git
synced 2026-10-01 08:43:15 +00:00
81 lines
3.1 KiB
C#
81 lines
3.1 KiB
C#
using FluentValidation;
|
|
using SeaHaven.Services.DTOs;
|
|
|
|
namespace SeaHaven.Services.Validation
|
|
{
|
|
public interface ICreateVendorValidation : IValidator<CreateVendorDTO>
|
|
{
|
|
}
|
|
|
|
public class CreateVendorValidation : AbstractValidator<CreateVendorDTO>, ICreateVendorValidation
|
|
{
|
|
public CreateVendorValidation()
|
|
{
|
|
RuleFor(x => x.Name)
|
|
.NotEmpty().WithMessage("Vendor name is required")
|
|
.MaximumLength(200).WithMessage("Vendor 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.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));
|
|
}
|
|
}
|
|
|
|
public interface IUpdateVendorValidation : IValidator<UpdateVendorDTO>
|
|
{
|
|
}
|
|
|
|
public class UpdateVendorValidation : AbstractValidator<UpdateVendorDTO>, IUpdateVendorValidation
|
|
{
|
|
public UpdateVendorValidation()
|
|
{
|
|
RuleFor(x => x.Name)
|
|
.MaximumLength(200).WithMessage("Vendor 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.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));
|
|
}
|
|
}
|
|
}
|