USP_DATAFORMTEMPLATE_COMM_ADD_SITEIMAGES

The save procedure used by the add dataform template "Image Add Data Form".

Parameters

Parameter Parameter Type Mode Description
@ID int INOUT The output parameter indicating the ID of the record added.
@CHANGEAGENTID uniqueidentifier IN Input parameter indicating the ID of the change agent invoking the procedure.
@NAME nvarchar(256) IN Name
@CAPTION nvarchar(256) IN Caption
@PHOTOGRAPHER nvarchar(256) IN Photographer
@CATEGORIES xml IN Categories
@PICTURE varbinary IN Image
@PICTUREFILENAME nvarchar(256) IN
@PICTUREFILENAMEEXT nvarchar(50) IN
@PICTURETYPE nvarchar(50) IN
@PICTURESIZE int IN
@DATETAKEN datetime IN Date taken

Definition

Copy

CREATE procedure dbo.[USP_DATAFORMTEMPLATE_COMM_ADD_SITEIMAGES]
(
  @ID integer output,
  @CHANGEAGENTID uniqueidentifier = null,
  @NAME nvarchar(256),
  @CAPTION nvarchar(256) = null,
  @PHOTOGRAPHER nvarchar(256) = null,
  @CATEGORIES xml = null,
  @PICTURE varbinary(max),
  @PICTUREFILENAME nvarchar(256),
  @PICTUREFILENAMEEXT nvarchar(50),
  @PICTURETYPE nvarchar(50),
  @PICTURESIZE int,
  @DATETAKEN datetime = null
)
as
  set nocount on;

  if exists (
    select top 1 1
    from dbo.SiteImages
    where 
      Name = @NAME
      and Deleted = 0
      and ClientSitesID = 1
  )
  begin
    raiserror('ERR_NAMEALREADYEXISTS',13,1);
    return 1
  end

  begin try
    declare @CATEGORIESNTEXT nvarchar(max) = cast((
      select 
        @ID as SiteImageID,
        ImageCategory.c.value('(ID)[1]','integer') as SiteFolderID
      from @CATEGORIES.nodes('/CATEGORIES/ITEM') ImageCategory(c)
      for xml auto,root('Image')
    ) as nvarchar(max))

    -- in order to use the existing BBNC save procedure, first we have to call it with dummy data (ID < 0)
    -- so that it will create a record, do other stuff, and return us the ID and filename

    set @ID = -1

    declare @FILENAME nvarchar(256),
      @GUID uniqueidentifier = newid()

    exec spAddUpdate_SiteImages 
      @ID output
      1, -- Current user
      1, -- Site
      null, -- Name
      @FILENAME output,
      @PICTUREFILENAMEEXT,
      null, -- Upload file name
      null, -- Image binary data
      null, -- Image mime type
      null, -- File size
      @GUID output
      0, -- Type
      null, -- Caption
      0, -- Approved
      0, -- Private
      null, -- Categories xml
      null, -- Album
      null, -- Photographer
      null, -- Date taken
      0 -- Deleted

    -- now we can feed it back what it just gave us... along with the rest of the real data.

    exec dbo.spAddUpdate_SiteImages
      @ID,
      1, -- Current user
      1, -- Site
      @NAME,
      @FILENAME,
      @PICTUREFILENAMEEXT,
      @PICTUREFILENAME,
      @PICTURE,
      @PICTURETYPE,
      @PICTURESIZE,
      @Guid,
      0, -- Type
      @CAPTION,
      1, -- Approved
      0, -- Private
      @CATEGORIESNTEXT,
      1, -- Album
      @PHOTOGRAPHER,
      @DATETAKEN,
      0 -- Deleted

  end try

  begin catch
      exec dbo.USP_RAISE_ERROR
      return 1
  end catch

  return 0