protected override object ReadRow(IRowReader reader) { AssetLink assetLink = AssetLink.New(); // Table Fields assetLink.AssetLinkId = reader.GetInt32("AssetLinkId"); assetLink.AssetId = reader.GetInt32("AssetId"); assetLink.LinkedAssetId = reader.GetInt32("LinkedAssetId"); // View Fields assetLink.LinkedAssetTitle = reader.GetString("LinkedAssetTitle"); assetLink.IsDirty = false; assetLink.ChangedProperties.Clear(); return(assetLink); }
public virtual AssetLink Update(AssetLink assetLink) { if (!assetLink.IsDirty || assetLink.IsNull) { // Nothing to do - no point hammering the database unnecessarily return(assetLink); } IDbCommand command = CreateCommand(); if (assetLink.IsNew) { // Adding command.CommandText = "INSERT INTO [AssetLink] ([AssetId], [LinkedAssetId]) VALUES (@assetId, @linkedAssetId) ; SELECT @@identity AS NewId;"; } else { // Updating command.CommandText = "UPDATE [AssetLink] SET [AssetId] = @assetId, [LinkedAssetId] = @linkedAssetId WHERE AssetLinkId = @assetLinkId"; } command.Parameters.Add(CreateParameter("@assetId", assetLink.AssetId)); command.Parameters.Add(CreateParameter("@linkedAssetId", assetLink.LinkedAssetId)); if (assetLink.IsNew) { assetLink.AssetLinkId = Convert.ToInt32(ExecScalar(command)); } else { command.Parameters.Add(CreateParameter("@assetLinkId", assetLink.AssetLinkId)); ExecuteCommand(command); } assetLink.IsDirty = false; assetLink.ChangedProperties.Clear(); return(assetLink); }
public static AssetLink FindOne(AssetLinkFinder finder) { AssetLink AssetLink = AssetLinkMapper.Instance.FindOne(finder); return(AssetLink ?? Empty); }
public static AssetLink Update(AssetLink assetLink) { return(AssetLinkMapper.Instance.Update(assetLink)); }
public static AssetLink Get(Nullable <Int32> AssetLinkId) { AssetLink AssetLink = AssetLinkMapper.Instance.Get(AssetLinkId); return(AssetLink ?? Empty); }
/// <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); } } }