mirror of
https://github.com/Sea-Haven-Industries/shoc-backend.git
synced 2026-09-30 14:13:12 +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 ICreateEmployeeValidation : IValidator<CreateEmployeeDTO>
|
|
{
|
|
}
|
|
|
|
public class CreateEmployeeValidation : AbstractValidator<CreateEmployeeDTO>, ICreateEmployeeValidation
|
|
{
|
|
public CreateEmployeeValidation()
|
|
{
|
|
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)
|
|
.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.DepartmentId)
|
|
.GreaterThan(0).WithMessage("Valid department must be selected")
|
|
.When(x => x.DepartmentId.HasValue);
|
|
|
|
RuleFor(x => x.JobTitleId)
|
|
.GreaterThan(0).WithMessage("Valid job title must be selected")
|
|
.When(x => x.JobTitleId.HasValue);
|
|
|
|
RuleFor(x => x.RegionId)
|
|
.GreaterThan(0).WithMessage("Valid region must be selected")
|
|
.When(x => x.RegionId.HasValue);
|
|
}
|
|
}
|
|
|
|
public interface IUpdateEmployeeValidation : IValidator<UpdateEmployeeDTO>
|
|
{
|
|
}
|
|
|
|
public class UpdateEmployeeValidation : AbstractValidator<UpdateEmployeeDTO>, IUpdateEmployeeValidation
|
|
{
|
|
public UpdateEmployeeValidation()
|
|
{
|
|
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.DepartmentId)
|
|
.GreaterThan(0).WithMessage("Valid department must be selected")
|
|
.When(x => x.DepartmentId.HasValue);
|
|
|
|
RuleFor(x => x.JobTitleId)
|
|
.GreaterThan(0).WithMessage("Valid job title must be selected")
|
|
.When(x => x.JobTitleId.HasValue);
|
|
|
|
RuleFor(x => x.RegionId)
|
|
.GreaterThan(0).WithMessage("Valid region must be selected")
|
|
.When(x => x.RegionId.HasValue);
|
|
}
|
|
}
|
|
}
|