PlotDirector/PlotLine/Sql/351_StoryAssetPreserveImageOnBaseSave.sql

38 lines
1.6 KiB
Transact-SQL

CREATE OR ALTER PROCEDURE dbo.StoryAsset_Save
@StoryAssetID int = NULL,
@ProjectID int,
@AssetName nvarchar(200),
@AssetKindID int,
@Description nvarchar(max) = NULL,
@Importance int,
@CurrentStateID int = NULL,
@CurrentLocationID int = NULL,
@IsResolved bit,
@ShowInQuickAddBar bit = 0,
@ImagePath nvarchar(500) = NULL,
@ThumbnailPath nvarchar(500) = NULL,
@PreserveImage bit = 0
AS
BEGIN
SET NOCOUNT ON;
IF @StoryAssetID IS NULL OR @StoryAssetID = 0
BEGIN
INSERT dbo.StoryAssets (ProjectID, AssetName, AssetKindID, Description, Importance, CurrentStateID, CurrentLocationID, IsResolved, ShowInQuickAddBar, ImagePath, ThumbnailPath)
VALUES (@ProjectID, @AssetName, @AssetKindID, @Description, @Importance, @CurrentStateID, @CurrentLocationID, @IsResolved, @ShowInQuickAddBar, @ImagePath, @ThumbnailPath);
SET @StoryAssetID = CAST(SCOPE_IDENTITY() AS int);
END
ELSE
BEGIN
UPDATE dbo.StoryAssets
SET AssetName = @AssetName, AssetKindID = @AssetKindID, Description = @Description, Importance = @Importance,
CurrentStateID = @CurrentStateID, CurrentLocationID = @CurrentLocationID, IsResolved = @IsResolved,
ShowInQuickAddBar = @ShowInQuickAddBar,
ImagePath = CASE WHEN @PreserveImage = 1 THEN ImagePath ELSE @ImagePath END,
ThumbnailPath = CASE WHEN @PreserveImage = 1 THEN ThumbnailPath ELSE @ThumbnailPath END,
UpdatedDate = SYSUTCDATETIME()
WHERE StoryAssetID = @StoryAssetID;
END
SELECT @StoryAssetID;
END;
GO