﻿


-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date, ,>
-- Description:	<Description, ,>
-- =============================================
CREATE PROCEDURE [dbo].[fis_admin_createUserAccount]
	@name nvarchar(100)
	,@firstname nvarchar(100)
	,@title varchar(50)
	,@gender varchar(1)
	,@email varchar(255)
	,@mobile varchar(50)
	,@password nvarchar(20)
	,@enc_key uniqueidentifier
AS
BEGIN
	SET NOCOUNT ON;

    DECLARE @utcnow datetime = GETUTCDATE();

	INSERT INTO [dbo].[fis_useraccounts]
           ([useraccount_id]
           ,[name_enc]
		   ,[firstname_enc]
		   ,[title_enc]
		   ,[gender_enc]
           ,[email_enc]
           ,[mobile_enc]
           ,[password_enc]
           ,[UserDisabled]
           ,[DateDisabled]
           ,[UserCreated]
           ,[DateCreated]
           ,[UserModified]
           ,[DateModified]
           ,[UserDeleted]
           ,[DateDeleted])
	 OUTPUT inserted.[useraccount_id]
     VALUES
           ([dbo].[fis_fn_useraccount_id] ()
           ,ENCRYPTBYKEY(@enc_key, @name)
		   ,ENCRYPTBYKEY(@enc_key, @firstname)
		   ,ENCRYPTBYKEY(@enc_key, @title)
		   ,ENCRYPTBYKEY(@enc_key, @gender)
           ,ENCRYPTBYKEY(@enc_key, @email)
           ,ENCRYPTBYKEY(@enc_key, @mobile)
           ,CASE WHEN @password is null then ENCRYPTBYKEY(@enc_key, CAST([dbo].[ocms_fn_generatePassword] (8, 0, 1, 1) AS nvarchar(20))) ELSE ENCRYPTBYKEY(@enc_key, @password) END
           ,NULL  --[UserDisabled]
           ,NULL  --[DateDisabled]
           ,'sa'
           ,@utcnow
           ,'sa'
           ,@utcnow
           ,NULL
           ,NULL);

END