Browse Source

Merge pull request #193 from EasyAbp/fix-create-update-product-dto

Fix a validation bug in `CreateUpdateProductDto`
pull/194/head
Super 4 years ago
committed by GitHub
parent
commit
3f128224dd
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 34
      modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application.Contracts/EasyAbp/EShop/Products/Products/Dtos/CreateUpdateProductDto.cs

34
modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application.Contracts/EasyAbp/EShop/Products/Products/Dtos/CreateUpdateProductDto.cs

@ -13,23 +13,23 @@ namespace EasyAbp.EShop.Products.Products.Dtos
{ {
[DisplayName("ProductStoreId")] [DisplayName("ProductStoreId")]
public Guid StoreId { get; set; } public Guid StoreId { get; set; }
[DisplayName("ProductProductGroupName")] [DisplayName("ProductProductGroupName")]
public string ProductGroupName { get; set; } public string ProductGroupName { get; set; }
[DisplayName("ProductDetailId")] [DisplayName("ProductDetailId")]
public Guid? ProductDetailId { get; set; } public Guid? ProductDetailId { get; set; }
[DisplayName("ProductCategory")] [DisplayName("ProductCategory")]
public ICollection<Guid> CategoryIds { get; set; } public ICollection<Guid> CategoryIds { get; set; }
[DisplayName("ProductUniqueName")] [DisplayName("ProductUniqueName")]
public string UniqueName { get; set; } public string UniqueName { get; set; }
[Required] [Required]
[DisplayName("ProductDisplayName")] [DisplayName("ProductDisplayName")]
public string DisplayName { get; set; } public string DisplayName { get; set; }
public ICollection<CreateUpdateProductAttributeDto> ProductAttributes { get; set; } public ICollection<CreateUpdateProductAttributeDto> ProductAttributes { get; set; }
[DisplayName("ProductInventoryStrategy")] [DisplayName("ProductInventoryStrategy")]
@ -46,10 +46,10 @@ namespace EasyAbp.EShop.Products.Products.Dtos
[DisplayName("ProductIsPublished")] [DisplayName("ProductIsPublished")]
public bool IsPublished { get; set; } public bool IsPublished { get; set; }
[DisplayName("ProductIsHidden")] [DisplayName("ProductIsHidden")]
public bool IsHidden { get; set; } public bool IsHidden { get; set; }
[DisplayName("ProductPaymentExpireIn")] [DisplayName("ProductPaymentExpireIn")]
public TimeSpan? PaymentExpireIn { get; set; } public TimeSpan? PaymentExpireIn { get; set; }
@ -64,7 +64,7 @@ namespace EasyAbp.EShop.Products.Products.Dtos
new[] { "PaymentExpireIn" } new[] { "PaymentExpireIn" }
); );
} }
if (ProductAttributes.Select(a => a.DisplayName.Trim()).Distinct().Count() != ProductAttributes.Count) if (ProductAttributes.Select(a => a.DisplayName.Trim()).Distinct().Count() != ProductAttributes.Count)
{ {
yield return new ValidationResult( yield return new ValidationResult(
@ -73,15 +73,17 @@ namespace EasyAbp.EShop.Products.Products.Dtos
); );
} }
var optionNameList = ProductAttributes.SelectMany(a => a.ProductAttributeOptions) foreach (var productAttribute in ProductAttributes)
.Select(o => o.DisplayName.Trim()).ToList();
if (optionNameList.Distinct().Count() != optionNameList.Count)
{ {
yield return new ValidationResult( var options = productAttribute.ProductAttributeOptions;
"DisplayNames of ProductAttributeOptions should be unique!",
new[] { "ProductAttributeOptions" } if (options.Select(o => o.DisplayName.Trim()).Distinct().Count() != options.Count)
); {
yield return new ValidationResult(
"DisplayNames of ProductAttributeOptions should be unique!",
new[] { "ProductAttributeOptions" }
);
}
} }
} }
} }

Loading…
Cancel
Save