public virtual AssetCategory Update(AssetCategory assetCategory) { if (!assetCategory.IsDirty || assetCategory.IsNull) { // Nothing to do - no point hammering the database unnecessarily return(assetCategory); } IDbCommand command = CreateCommand(); if (assetCategory.IsNew) { // Adding command.CommandText = "INSERT INTO [AssetCategory] ([AssetId], [CategoryId], [IsPrimary]) VALUES (@assetId, @categoryId, @isPrimary) ; SELECT @@identity AS NewId;"; } else { // Updating command.CommandText = "UPDATE [AssetCategory] SET [AssetId] = @assetId, [CategoryId] = @categoryId, [IsPrimary] = @isPrimary WHERE AssetCategoryId = @assetCategoryId"; } command.Parameters.Add(CreateParameter("@assetId", assetCategory.AssetId)); command.Parameters.Add(CreateParameter("@categoryId", assetCategory.CategoryId)); command.Parameters.Add(CreateParameter("@isPrimary", assetCategory.IsPrimary)); if (assetCategory.IsNew) { assetCategory.AssetCategoryId = Convert.ToInt32(ExecScalar(command)); } else { command.Parameters.Add(CreateParameter("@assetCategoryId", assetCategory.AssetCategoryId)); ExecuteCommand(command); } assetCategory.IsDirty = false; assetCategory.ChangedProperties.Clear(); return(assetCategory); }
protected override object ReadRow(IRowReader reader) { AssetCategory assetCategory = AssetCategory.New(); // Table Fields assetCategory.AssetCategoryId = reader.GetInt32("AssetCategoryId"); assetCategory.AssetId = reader.GetInt32("AssetId"); assetCategory.CategoryId = reader.GetInt32("CategoryId"); assetCategory.IsPrimary = reader.GetBoolean("IsPrimary"); // View Fields assetCategory.Name = reader.GetString("Name"); assetCategory.ParentCategoryId = reader.GetNullableInt32("ParentCategoryId"); assetCategory.Synonyms = reader.GetString("Synonyms"); assetCategory.CategoryOrder = reader.GetInt32("CategoryOrder"); assetCategory.NameAndSynonyms = reader.GetString("NameAndSynonyms"); assetCategory.IsDirty = false; assetCategory.ChangedProperties.Clear(); return(assetCategory); }
public static AssetCategory FindOne(AssetCategoryFinder finder) { AssetCategory AssetCategory = AssetCategoryMapper.Instance.FindOne(finder); return(AssetCategory ?? Empty); }
public static AssetCategory Update(AssetCategory assetCategory) { return(AssetCategoryMapper.Instance.Update(assetCategory)); }
public static AssetCategory Get(Nullable <Int32> AssetCategoryId) { AssetCategory AssetCategory = AssetCategoryMapper.Instance.Get(AssetCategoryId); return(AssetCategory ?? 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); } } }