From 1751216a2ea1a8fb5aa307e0cacb79bd3e67751f Mon Sep 17 00:00:00 2001 From: malik masis Date: Tue, 16 Aug 2022 17:34:01 +0300 Subject: [PATCH] Added validation to `EntityTagSetDto` for Tags --- .../Volo/CmsKit/Admin/Tags/EntityTagSetDto.cs | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Tags/EntityTagSetDto.cs b/modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Tags/EntityTagSetDto.cs index 245526cfc2..33afb68a6e 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Tags/EntityTagSetDto.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Tags/EntityTagSetDto.cs @@ -1,15 +1,28 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.ComponentModel.DataAnnotations; +using Volo.CmsKit.Tags; namespace Volo.CmsKit.Admin.Tags; [Serializable] -public class EntityTagSetDto +public class EntityTagSetDto : IValidatableObject { public string EntityId { get; set; } public string EntityType { get; set; } public List Tags { get; set; } + + public IEnumerable Validate(ValidationContext validationContext) + { + foreach (var tag in Tags) + { + if (tag.Length > TagConsts.MaxNameLength) + { + yield return new ValidationResult( + $"{nameof(tag)} length must be equal to or lower than {TagConsts.MaxNameLength}", + new[] { nameof(Tags) } + ); + } + } + } }