private TypicalListData ToTypicalListData(Typical t) { return(new TypicalListData() { TypicalID = t.TypicalID, Name = t.Name, SeriesID = t.SeriesTypicals.Where(st => st.IsPrimary).Select(st => st.SeriesID).FirstOrDefault(), ImageFileData = t.FeaturedImageForSize("m16to9"), FeaturedSeries = t.FeaturedSeries }); }
public TypicalInformation GetTypicalInfo(int?id = null, string typicalName = null) { TypicalInformation tInfo = new TypicalInformation(); Typical theData = null; if (id.HasValue) { theData = database.Typicals.FirstOrDefault(s => s.TypicalID == id); } else if ((typicalName ?? "").Any()) { theData = database.Typicals.FirstOrDefault(s => s.Name == typicalName); } if (theData != null) { tInfo.TypicalID = theData.TypicalID; tInfo.Name = theData.Name; var serTypical = theData.SeriesTypicals.FirstOrDefault(st => st.IsPrimary); if (serTypical != null) { tInfo.Category = serTypical.Series.Category.Name; tInfo.Series = serTypical.Series.Name; } tInfo.FeaturedImageFileData = theData.FeaturedImageForSize("l16to9"); tInfo.Images = theData.ImageListForSize("m16to9", 3).Select(i => (ImageComboItem)i).ToList(); tInfo.Options = new Dictionary <string, IEnumerable <string> >(); tInfo.Details = new Dictionary <string, IEnumerable <string> >(); foreach (var attr in theData.TypicalOptionAttributes.Select(soa => soa.TAttribute).Distinct()) { if (attr.DetailItem) { tInfo.Details.Add(attr.Name, new List <string>( theData.TypicalOptionAttributes .Where(soa => soa.AttributeID == attr.AttributeID) .Select(so => so.TAttributeOption.Name) )); } else { tInfo.Options.Add(attr.Name, new List <string>( theData.TypicalOptionAttributes .Where(soa => soa.AttributeID == attr.AttributeID) .Select(so => so.TAttributeOption.Name) )); } } foreach (var attr in theData.TypicalIntAttributes.Select(soa => soa.TAttribute).Distinct()) { if (attr.DetailItem) { tInfo.Details.Add(attr.Name, new List <string>( theData.TypicalIntAttributes .Where(soa => soa.AttributeID == attr.AttributeID) .Select(so => so.Value.ToString()) )); } else { tInfo.Options.Add(attr.Name, new List <string>( theData.TypicalIntAttributes .Where(soa => soa.AttributeID == attr.AttributeID) .Select(so => so.Value.ToString()) )); } } foreach (var attr in theData.TypicalTextAttributes.Select(soa => soa.TAttribute).Distinct()) { if (attr.DetailItem) { tInfo.Details.Add(attr.Name, new List <string>( theData.TypicalTextAttributes .Where(soa => soa.AttributeID == attr.AttributeID) .Select(so => so.Value) )); } else { tInfo.Options.Add(attr.Name, new List <string>( theData.TypicalTextAttributes .Where(soa => soa.AttributeID == attr.AttributeID) .Select(so => so.Value) )); } } } return(tInfo); }