public static BlogPostTypes GetBlogPostType(this ContentPart contentPart) { EnumerationField field = (EnumerationField)contentPart.Fields.SingleOrDefault(f => f.Name == "BlogPostType"); if (field == null) { return(BlogPostTypes.Image); } BlogPostTypes blogPostType; if (Enum.TryParse(field.Value, true, out blogPostType)) { return(blogPostType); } return(BlogPostTypes.Image); }
protected override void Exporting(ContentPart part, EnumerationField field, ExportContentContext context) { context.Element(field.FieldDefinition.Name + "." + field.Name).SetAttributeValue("Value", field.Value); }
public HttpResponseMessage Get() { var shoppingCartModel = new ShoppingCartModel(); //var query = _shoppingCart.GetProducts().Select(tuple => _shapeFactory.ShoppingCartItem( // Product: tuple.Item1, // ContentItem: tuple.Item1.ContentItem, // Quantity: tuple.Item2 //)); var query = _shoppingCart.GetProducts(); var enumerable = query as IList <Tuple <ProductPart, int> > ?? query.ToList(); var itemCount = 0; foreach (var tuple in enumerable) { var contentItem = (ContentItem)tuple.Item1.ContentItem; var productId = contentItem.Id; var titlePart = contentItem.As <TitlePart>(); var title = titlePart != null ? titlePart.Title : "(no titlePart attached)"; itemCount += tuple.Item2; ContentPart contentPart = null; foreach (var part in tuple.Item1.ContentItem.Parts.Where(part => part.GetType() == typeof(ContentPart))) { contentPart = part; } EnumerationField enumerationField = null; if (contentPart != null) { foreach (var contentField in contentPart.Fields.Where(contentField => contentField.GetType() == typeof(EnumerationField))) { enumerationField = (EnumerationField)contentField; } } var sizeArray = new[] { "No Size" }; if (enumerationField != null) { // Read the connection string from the *local* web.config (not the root). var fileMap = new ExeConfigurationFileMap(); fileMap.ExeConfigFilename = HttpContext.Current.Server.MapPath("~/Modules/ivNet.WebStore/web.config"); var configuration = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None); var sizeArrayValues = configuration.AppSettings.Settings[enumerationField.Value]; if (sizeArrayValues != null) { sizeArray = sizeArrayValues.Value.Split(','); } } shoppingCartModel.ShopItems.Add(new ShoppingCartItemModel { ProductId = productId, Quantity = tuple.Item2, Title = title, Price = tuple.Item1.Price, Sku = tuple.Item1.Sku, Sizes = sizeArray }); } shoppingCartModel.ItemCount = itemCount; //shoppingCartModel.Total = _shoppingCart.Total(); //shoppingCartModel.Subtotal = _shoppingCart.Subtotal(); //shoppingCartModel.Vat = _shoppingCart.Vat(); return(Request.CreateResponse(HttpStatusCode.OK, shoppingCartModel)); }
protected override void Importing(ContentPart part, EnumerationField field, ImportContentContext context) { context.ImportAttribute(field.FieldDefinition.Name + "." + field.Name, "Value", v => field.Value = v); }