34 lines
1.0 KiB
C#
34 lines
1.0 KiB
C#
using System.ComponentModel.DataAnnotations;
|
|
|
|
namespace T120B165_ImgBoard.Dtos.Post;
|
|
|
|
public record CreatePostDto(string Title,
|
|
[Required]
|
|
string Description,
|
|
[Required]
|
|
List<string> Tags,
|
|
[Required]
|
|
string FileName,
|
|
[Required]
|
|
string FileMimeType,
|
|
[Required]
|
|
[Range(0, long.MaxValue, ErrorMessage = "The {0} must be a valid number and at least {1}.")]
|
|
long? FileSize
|
|
);
|
|
|
|
public record EditPostDto(string? Title, string? Description, List<string>? Tags): IValidatableObject
|
|
{
|
|
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
|
{
|
|
var allEmpty = string.IsNullOrWhiteSpace(Title) &&
|
|
string.IsNullOrWhiteSpace(Description) &&
|
|
Tags == null;
|
|
if (allEmpty)
|
|
{
|
|
yield return new ValidationResult(
|
|
"You must provide at least one value to edit: Title, Description, or Tags.",
|
|
[nameof(Title), nameof(Description), nameof(Tags)]
|
|
);
|
|
}
|
|
}
|
|
} |