public VipBaoYangPackageViewModel(VipBaoYangPackageDbModel package) { if (package != null) { if (string.IsNullOrEmpty(package.Brands)) { this.Brands = new List <BaoYangPackageOilBrand>(); } else if (package.Brands.Contains('[') || package.Brands.Contains(']')) { this.Brands = JsonConvert.DeserializeObject <List <BaoYangPackageOilBrand> >(package.Brands ?? string.Empty) ?? new List <BaoYangPackageOilBrand>(); } else { this.Brands = package.Brands.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries) .Select(brand => new BaoYangPackageOilBrand { Brand = brand, Grades = new List <int> { 1, 2, 3 }, }).ToList(); } this.PKID = package.PKID; this.PID = package.PID; this.PackageName = package.PackageName; this.CreateUser = package.CreateUser; this.Price = package.Price; this.SettlementMethod = package.SettlementMethod; this.VipUserId = package.VipUserId; this.Volume = package.Volume; } }
public VipBaoYangPackageViewModel(VipBaoYangPackageDbModel package) { if (package != null) { this.OilConfigs = package?.OilConfigs.OrderBy(x => x.PKID).Select(x => new BaoYangPackageOilConfig { Brand = x.Brand, Grade = x.Grade, Series = x.Series, }).ToList() ?? new List <BaoYangPackageOilConfig>(); this.PKID = package.PKID; this.PID = package.PID; this.PackageName = package.PackageName; this.CreateUser = package.CreateUser; this.Price = package.Price; this.SettlementMethod = package.SettlementMethod; this.VipUserId = package.VipUserId; this.Volume = package.Volume; } }