using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Store.Product.Models.Product.Sku { /// /// Sku属性 /// public class SkuPropertys : List { public SkuPropertys() { } /// /// 是否存在Key /// /// /// public bool ContainsKey(string Id) { return Exists(a => a.Id == Id); } /// /// 添加Sku属性 /// /// /// public void AddSkuProperty(string id, string name) { if (!ContainsKey(id)) { this.Add(new SkuProperty { Id = id, Name = name, Values = new List() }); } } /// /// 添加Sku属性 包含值 /// /// /// public void AddSkuPropertyItem(string id, SkuPropertyItem propertyItem) { if (propertyItem != null) { var item = GetPropertyById(id); if (!item.Values.Exists(a => a.Id == propertyItem.Id)) { item.Values.Add(propertyItem); } } } //public void AddSkuProperty(string id, string name, SkuPropertyItem propertyItem) //{ //} /// /// 获取Sku属性值 /// /// /// /// public SkuMapProperty GetSkuMapProperty(string name, string itemname) { SkuProperty p = this.FirstOrDefault(a => a.Name == name); if (p != null) { var item = p.Values.FirstOrDefault(a => a.Name == itemname); return new SkuMapProperty() { Id = p.Id, Name = p.Name, Item = item }; } return null; } /// /// 获取值 /// /// /// public SkuProperty GetPropertyById(string Id) { if (ContainsKey(Id)) { SkuProperty p = this.FirstOrDefault(a => a.Id == Id); return p; } return null; } } }