Esempio n. 1
0
        protected override object ReadRow(IRowReader reader)
        {
            AssetMetadataTextArea assetMetadataTextArea = AssetMetadataTextArea.New();

            // Table Fields
            assetMetadataTextArea.AssetMetadataTextAreaId = reader.GetInt32("AssetMetadataTextAreaId");
            assetMetadataTextArea.AssetId       = reader.GetInt32("AssetId");
            assetMetadataTextArea.GroupNumber   = reader.GetInt32("GroupNumber");
            assetMetadataTextArea.TextAreaValue = reader.GetString("TextAreaValue");

            assetMetadataTextArea.IsDirty = false;
            assetMetadataTextArea.ChangedProperties.Clear();

            return(assetMetadataTextArea);
        }
Esempio n. 2
0
        public virtual AssetMetadataTextArea Update(AssetMetadataTextArea assetMetadataTextArea)
        {
            if (!assetMetadataTextArea.IsDirty || assetMetadataTextArea.IsNull)
            {
                // Nothing to do - no point hammering the database unnecessarily
                return(assetMetadataTextArea);
            }

            IDbCommand command = CreateCommand();

            if (assetMetadataTextArea.IsNew)
            {
                // Adding
                command.CommandText = @"INSERT INTO [AssetMetadataTextArea] ([AssetId], [GroupNumber], [TextAreaValue]) VALUES (@assetId, @groupNumber, @textAreaValue) ; SELECT @@identity AS NewId;";
            }
            else
            {
                // Updating
                command.CommandText = "UPDATE [AssetMetadataTextArea] SET [AssetId] = @assetId, [GroupNumber] = @groupNumber, [TextAreaValue] = @textAreaValue WHERE AssetMetadataTextAreaId = @assetMetadataTextAreaId";
            }

            command.Parameters.Add(CreateParameter("@assetId", assetMetadataTextArea.AssetId));
            command.Parameters.Add(CreateParameter("@groupNumber", assetMetadataTextArea.GroupNumber));
            command.Parameters.Add(CreateParameter("@textAreaValue", assetMetadataTextArea.TextAreaValue));

            if (assetMetadataTextArea.IsNew)
            {
                assetMetadataTextArea.AssetMetadataTextAreaId = Convert.ToInt32(ExecScalar(command));
            }
            else
            {
                command.Parameters.Add(CreateParameter("@assetMetadataTextAreaId", assetMetadataTextArea.AssetMetadataTextAreaId));
                ExecuteCommand(command);
            }

            assetMetadataTextArea.IsDirty = false;
            assetMetadataTextArea.ChangedProperties.Clear();

            return(assetMetadataTextArea);
        }
Esempio n. 3
0
        public static AssetMetadataTextArea FindOne(AssetMetadataTextAreaFinder finder)
        {
            AssetMetadataTextArea AssetMetadataTextArea = AssetMetadataTextAreaMapper.Instance.FindOne(finder);

            return(AssetMetadataTextArea ?? Empty);
        }
Esempio n. 4
0
 public static AssetMetadataTextArea Update(AssetMetadataTextArea assetMetadataTextArea)
 {
     return(AssetMetadataTextAreaMapper.Instance.Update(assetMetadataTextArea));
 }
Esempio n. 5
0
        public static AssetMetadataTextArea Get(Nullable <Int32> AssetMetadataTextAreaId)
        {
            AssetMetadataTextArea AssetMetadataTextArea = AssetMetadataTextAreaMapper.Instance.Get(AssetMetadataTextAreaId);

            return(AssetMetadataTextArea ?? Empty);
        }
Esempio n. 6
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);
                }
            }
        }