protected override dynamic GetData() { string url = string.Format("/{0}", this.requestHandler.HttpContext.GetRouteValue("url")); SerializedProduct serializedProduct = this.requestHandler.Storage.GetRepository <ISerializedProductRepository>().WithUrl(url); if (serializedProduct == null) { throw new HttpException(404, "Not found."); } IEnumerable <SerializedProduct.Attribute> serializedAttributes = JsonConvert.DeserializeObject <IEnumerable <SerializedProduct.Attribute> >(serializedProduct.SerializedAttributes); IEnumerable <SerializedProduct.Photo> serializedPhotos = JsonConvert.DeserializeObject <IEnumerable <SerializedProduct.Photo> >(serializedProduct.SerializedPhotos); SerializedProduct.Photo serializedCoverPhoto = serializedPhotos.FirstOrDefault(sph => sph.IsCover); return(new ExpandoObjectBuilder() .AddProperty("Id", serializedProduct.ProductId) .AddProperty("Code", serializedProduct.Code) .AddProperty("Name", serializedProduct.Name) .AddProperty("Description", serializedProduct.Description) .AddProperty("Price", serializedProduct.Price) .AddProperty("Title", serializedProduct.Title) .AddProperty("MetaDescription", serializedProduct.MetaDescription) .AddProperty("MetaKeywords", serializedProduct.MetaKeywords) .AddProperty("Attributes", serializedAttributes.OrderBy(sa => sa.Feature.Position).Select(sa => this.CreateAttributeViewModel(sa))) .AddProperty("CoverPhoto", this.CreatePhotoViewModel(serializedCoverPhoto)) .AddProperty("Photos", serializedPhotos.OrderBy(sph => sph.Position).Select(sph => this.CreatePhotoViewModel(sph))) .Build()); }
private SerializedProduct.Photo SerializePhoto(Culture culture, Photo photo) { SerializedProduct.Photo serializedPhoto = new SerializedProduct.Photo(); serializedPhoto.Filename = photo.Filename; serializedPhoto.IsCover = photo.IsCover; serializedPhoto.Position = photo.Position; return(serializedPhoto); }
private dynamic CreatePhotoViewModel(SerializedProduct.Photo serializedPhoto) { if (serializedPhoto == null) { return(null); } return(new ExpandoObjectBuilder() .AddProperty("Filename", serializedPhoto.Filename) .Build()); }
private dynamic CreateProductViewModel(SerializedProduct serializedProduct) { IEnumerable <SerializedProduct.Photo> serializedPhotos = JsonConvert.DeserializeObject <IEnumerable <SerializedProduct.Photo> >(serializedProduct.SerializedPhotos); SerializedProduct.Photo serializedCoverPhoto = serializedPhotos.FirstOrDefault(sph => sph.IsCover); return(new ExpandoObjectBuilder() .AddProperty("Id", serializedProduct.ProductId) .AddProperty("Url", serializedProduct.Url) .AddProperty("Code", serializedProduct.Code) .AddProperty("Name", serializedProduct.Name) .AddProperty("Price", serializedProduct.Price) .AddProperty("CoverPhoto", this.CreatePhotoViewModel(serializedCoverPhoto)) .Build()); }