public ActionResult Index()
        {
            var contentTypeModels = _contentTypeModelRepository.List();
            var model             = new ContentTypeAnalyzerModel
            {
                ContentTypes = CreateContentTypeModels(contentTypeModels)
            };

            return(View(model));
        }
        private Dictionary <string, ContentTypeModel> PopulateMetadataMappings()
        {
            var mappings = new Dictionary <string, ContentTypeModel>(StringComparer.OrdinalIgnoreCase);

            foreach (var contentTypeModel in _contentTypeModelRepository.List())
            {
                if (!typeof(CatalogContentBase).IsAssignableFrom(contentTypeModel.ModelType))
                {
                    continue;
                }

                if (contentTypeModel.Attributes.TryGetSingleAttribute(out CatalogContentTypeAttribute attribute) &&
                    !string.IsNullOrWhiteSpace(attribute.MetaClassName))
                {
                    mappings.Add(attribute.MetaClassName, contentTypeModel);
                }
            }

            return(mappings);
        }
Ejemplo n.º 3
0
        public IEnumerable <IModelTransformContext> Execute(IEnumerable <IModelTransformContext> models)
        {
            var modelList = models.ToList();

            foreach (var model in modelList)
            {
                var facetContent = model.Source as IFacetContent;
                if (facetContent != null)
                {
                    var properties = model.Target.Properties;

                    properties["MetaClassName"] = MetaHelper.LoadMetaClassCached(CatalogContext.MetaDataContext, facetContent.MetaClassId).FriendlyName;
                    properties["StartPublish"]  = facetContent.StartPublish;
                    properties["StopPublish"]   = facetContent.StopPublish;

                    var contentType      = _contentTypeRepository.Load(facetContent.ContentTypeID);
                    var contentTypeModel = _contentTypeModelRepository.List()
                                           .FirstOrDefault(x => x.ExistingContentType == contentType);
                    if (contentTypeModel == null)
                    {
                        continue;
                    }

                    if (typeof(EntryContentBase).IsAssignableFrom(contentTypeModel.ModelType))
                    {
                        properties["Code"] = facetContent.Code;
                    }

                    if (typeof(VariationContent).IsAssignableFrom(contentTypeModel.ModelType))
                    {
                        properties["Price"] = facetContent.DefaultPrice.ToString();

                        var instockQuantity    = facetContent.Inventories.Sum(x => x.InStockQuantity);
                        var reorderMinQuantity = facetContent.Inventories.Max(x => x.ReorderMinQuantity);

                        string status;
                        if (instockQuantity == 0)
                        {
                            status = "unavailable";
                        }
                        else if (instockQuantity < reorderMinQuantity)
                        {
                            status = "low";
                        }
                        else
                        {
                            status = "available";
                        }

                        properties["InStockStatus"]   = status;
                        properties["InStockQuantity"] = instockQuantity.ToString();
                    }

                    if (typeof(NodeContent).IsAssignableFrom(contentTypeModel.ModelType))
                    {
                        properties["Code"] = facetContent.Code;
                    }

                    if (typeof(CatalogContent).IsAssignableFrom(contentTypeModel.ModelType))
                    {
                        properties["WeightBase"]      = facetContent.WeightBase;
                        properties["DefaultCurrency"] = facetContent.DefaultCurrency;
                        properties["LengthBase"]      = facetContent.LengthBase;
                    }

                    if (typeof(IAssetContainer).IsAssignableFrom(contentTypeModel.ModelType))
                    {
                        properties["Thumbnail"] = facetContent.ThumbnailPath;
                    }

                    model.Target.TypeIdentifier = contentTypeModel.ModelType.FullName.ToLowerInvariant();

                    SetCurrentCategoryRelation(model, properties, facetContent);
                    SetHasChildrenForEntryContent(model, facetContent);

                    //        var catalogProperties = new Dictionary<string, Func<object, object>>
                    //    {
                    //        {CatalogProperty(c => c.DefaultLanguage), GetTranslatedLanguage},
                    //        {CatalogProperty(c => c.Owner), getDefaultValue}
                    //    };
                }
            }

            return(modelList);
        }