Ejemplo n.º 1
0
        public static AssetMetadata FindOne(AssetMetadataFinder finder)
        {
            AssetMetadata AssetMetadata = AssetMetadataMapper.Instance.FindOne(finder);

            return(AssetMetadata ?? Empty);
        }
Ejemplo n.º 2
0
        public static AssetMetadata Get(Nullable <Int32> AssetMetadataId)
        {
            AssetMetadata AssetMetadata = AssetMetadataMapper.Instance.Get(AssetMetadataId);

            return(AssetMetadata ?? Empty);
        }
Ejemplo n.º 3
0
 public static AssetMetadata Update(AssetMetadata assetMetadata)
 {
     return(AssetMetadataMapper.Instance.Update(assetMetadata));
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Saves the asset metadata.
        /// </summary>
        public static void SaveAssetMetadata(Asset asset)
        {
            if (asset.IsNull)
            {
                Debug.WriteLine("Skipped saving asset metadata, asset is null");
                return;
            }

            if (asset.IsNew)
            {
                Debug.WriteLine("Skipped saving asset metadata, asset is new");
                return;
            }

            if (asset.AssetMetadataLoaded())
            {
                AssetMetadataMapper.Instance.DeleteAllAssetMetadata(asset.AssetId.GetValueOrDefault());

                StringBuilder sb = new StringBuilder();

                foreach (var metadata in asset.MetadataList.Distinct())
                {
                    if (metadata.IsNull || metadata.MetadataId == 0)
                    {
                        continue;
                    }

                    AssetMetadata am = AssetMetadata.New();
                    am.AssetId    = asset.AssetId.GetValueOrDefault();
                    am.MetadataId = metadata.MetadataId.GetValueOrDefault();
                    AssetMetadata.Update(am);

                    sb.AppendFormat(" {0}", metadata.Name);

                    if (!StringUtils.IsBlank(metadata.ExternalRef))
                    {
                        sb.AppendFormat(", {0}", metadata.ExternalRef);
                    }

                    if (!StringUtils.IsBlank(metadata.Synonyms))
                    {
                        sb.AppendFormat(", {0}", metadata.Synonyms);
                    }
                }

                foreach (var area in asset.MetadataTextAreasList)
                {
                    if (area.IsNull || StringUtils.IsBlank(area.TextAreaValue))
                    {
                        continue;
                    }

                    area.AssetMetadataTextAreaId = null;
                    area.AssetId = asset.AssetId.GetValueOrDefault();
                    AssetMetadataTextArea.Update(area);

                    sb.AppendFormat(" {0}", area.TextAreaValue.Length > 600 ? area.TextAreaValue.Substring(0, 600) : area.TextAreaValue);
                }

                foreach (var field in asset.MetadataTextFieldsList)
                {
                    if (field.IsNull || StringUtils.IsBlank(field.TextFieldValue))
                    {
                        continue;
                    }

                    field.AssetMetadataTextFieldId = null;
                    field.AssetId = asset.AssetId.GetValueOrDefault();
                    AssetMetadataTextField.Update(field);

                    sb.AppendFormat(" {0}", field.TextFieldValue);
                }

                asset.AssetMetadataVals = sb.ToString().Trim();
                Update(asset);
            }

            if (asset.AssetCategoriesLoaded())
            {
                AssetCategoryMapper.Instance.DeleteAssetCategories(asset.AssetId.GetValueOrDefault());

                StringBuilder sb = new StringBuilder();

                foreach (Category category in asset.CategoryList)
                {
                    if (category.IsNull)
                    {
                        continue;
                    }

                    AssetCategory ac = AssetCategory.New();
                    ac.AssetId    = asset.AssetId.GetValueOrDefault();
                    ac.CategoryId = category.CategoryId.GetValueOrDefault();
                    ac.IsPrimary  = (asset.PrimaryCategoryId == ac.CategoryId);
                    AssetCategory.Update(ac);

                    sb.Append(category.Name);

                    //if (!StringUtils.IsBlank(category.Message))
                    //	sb.AppendFormat(", {0}", category.Message);

                    if (!StringUtils.IsBlank(category.ExternalRef))
                    {
                        sb.AppendFormat(", {0}", category.ExternalRef);
                    }

                    if (!StringUtils.IsBlank(category.Synonyms))
                    {
                        sb.AppendFormat(", {0}", category.Synonyms);
                    }
                }

                asset.AssetCategories = sb.ToString();
                Update(asset);
            }

            if (asset.LinkedAssetsLoaded())
            {
                AssetLinkMapper.Instance.DeleteLinkedAssets(asset.AssetId.GetValueOrDefault());

                foreach (Asset linkedAsset in asset.LinkedAssetList)
                {
                    if (linkedAsset.IsNull)
                    {
                        continue;
                    }

                    AssetLink assetLink = AssetLink.New();
                    assetLink.AssetId          = asset.AssetId.GetValueOrDefault();
                    assetLink.LinkedAssetId    = linkedAsset.AssetId.GetValueOrDefault();
                    assetLink.LinkedAssetTitle = linkedAsset.Title;                     // Not really required, controlled by the view anyway
                    AssetLink.Update(assetLink);
                }
            }
        }