mirror of
https://github.com/Sea-Haven-Industries/shoc-backend.git
synced 2026-09-30 16:33:12 +00:00
41 lines
1.3 KiB
C#
41 lines
1.3 KiB
C#
using FluentValidation;
|
|
using SeaHaven.Services.DTOs;
|
|
|
|
namespace SeaHaven.Services.Validation
|
|
{
|
|
public interface ICreateAssetValidation : IValidator<CreateAssetDTO>
|
|
{
|
|
}
|
|
|
|
public class CreateAssetValidation : AbstractValidator<CreateAssetDTO>, ICreateAssetValidation
|
|
{
|
|
public CreateAssetValidation()
|
|
{
|
|
RuleFor(x => x.Name)
|
|
.NotEmpty().WithMessage("Asset name is required")
|
|
.MaximumLength(200).WithMessage("Asset name cannot exceed 200 characters");
|
|
|
|
RuleFor(x => x.LocationId)
|
|
.GreaterThan(0).WithMessage("Valid location must be selected")
|
|
.When(x => x.LocationId.HasValue);
|
|
}
|
|
}
|
|
|
|
public interface IUpdateAssetValidation : IValidator<UpdateAssetDTO>
|
|
{
|
|
}
|
|
|
|
public class UpdateAssetValidation : AbstractValidator<UpdateAssetDTO>, IUpdateAssetValidation
|
|
{
|
|
public UpdateAssetValidation()
|
|
{
|
|
RuleFor(x => x.Name)
|
|
.MaximumLength(200).WithMessage("Asset name cannot exceed 200 characters")
|
|
.When(x => !string.IsNullOrEmpty(x.Name));
|
|
|
|
RuleFor(x => x.LocationId)
|
|
.GreaterThan(0).WithMessage("Valid location must be selected")
|
|
.When(x => x.LocationId.HasValue);
|
|
}
|
|
}
|
|
}
|