Browse Source

Added validation for Tags and its elements

pull/13718/head
malik masis 4 years ago
parent
commit
c192699752
  1. 15
      modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Tags/EntityTagSetDto.cs
  2. 3
      modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Localization/Resources/en.json
  3. 3
      modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Localization/Resources/tr.json

15
modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Tags/EntityTagSetDto.cs

@ -1,6 +1,9 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Localization;
using Volo.CmsKit.Localization;
using Volo.CmsKit.Tags; using Volo.CmsKit.Tags;
namespace Volo.CmsKit.Admin.Tags; namespace Volo.CmsKit.Admin.Tags;
@ -9,17 +12,27 @@ namespace Volo.CmsKit.Admin.Tags;
public class EntityTagSetDto : IValidatableObject public class EntityTagSetDto : IValidatableObject
{ {
public string EntityId { get; set; } public string EntityId { get; set; }
public string EntityType { get; set; } public string EntityType { get; set; }
[Required]
public List<string> Tags { get; set; } public List<string> Tags { get; set; }
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext) public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
{ {
var l = validationContext.GetRequiredService<IStringLocalizer<CmsKitResource>>();
foreach (var tag in Tags) foreach (var tag in Tags)
{ {
if (tag.Length > TagConsts.MaxNameLength) if (tag.Length > TagConsts.MaxNameLength)
{ {
yield return new ValidationResult( yield return new ValidationResult(
$"{nameof(tag)} length must be equal to or lower than {TagConsts.MaxNameLength}", l[
"MaxTagLengthExceptionMessage",
nameof(tag),
TagConsts.MaxNameLength,
typeof(EntityTagSetDto).FullName
],
new[] { nameof(Tags) } new[] { nameof(Tags) }
); );
} }

3
modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Localization/Resources/en.json

@ -206,6 +206,7 @@
"Feature:ReactionEnable": "Enabled reaction", "Feature:ReactionEnable": "Enabled reaction",
"Feature:ReactionEnableDescription": "Enable reaction in the application.", "Feature:ReactionEnableDescription": "Enable reaction in the application.",
"Feature:TagEnable": "Enabled taging", "Feature:TagEnable": "Enabled taging",
"Feature:TagEnableDescription": "Enable taging in the application." "Feature:TagEnableDescription": "Enable taging in the application.",
"MaxTagLengthExceptionMessage": "{0} length must be equal to or lower than {1}. {2}"
} }
} }

3
modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Localization/Resources/tr.json

@ -209,6 +209,7 @@
"Feature:ReactionEnable": "Reaksiyonları etkinleştirin", "Feature:ReactionEnable": "Reaksiyonları etkinleştirin",
"Feature:ReactionEnableDescription": "Uygulamınızdaki reaksiyonları etkinleştirir.", "Feature:ReactionEnableDescription": "Uygulamınızdaki reaksiyonları etkinleştirir.",
"Feature:TagEnable": "Etkiketleri etkinleştirin", "Feature:TagEnable": "Etkiketleri etkinleştirin",
"Feature:TagEnableDescription": "Uygulamınızdaki etiketleri etkinleştirir." "Feature:TagEnableDescription": "Uygulamınızdaki etiketleri etkinleştirir.",
"MaxTagLengthExceptionMessage": "{0} uzunluğu {1} den küçük veya eşit olmalı. {2}"
} }
} }

Loading…
Cancel
Save