Add project files
This commit is contained in:
34
T120B165-ImgBoard/Dtos/Post/CreatePostDto.cs
Normal file
34
T120B165-ImgBoard/Dtos/Post/CreatePostDto.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
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)]
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user