CREATE PROCEDURE [dbo].[USP_MM_INSUPDUserDetails] (
@UserDetailID int=0, --if zero the new record otherwise update
@UserID int=0, --if zero then new record
@FirstName varchar(50),
@LastName varchar(50),
@Address1 varchar(500),
@Address2 varchar(500)=null,
@CityId int,
@StateId int,
@ZipCode nvarchar(50),
@CountryId int,
@Phone varchar(20),
@EmailID nvarchar(50),
@AlternateEmailID nvarchar(50),
@DateOfBirth datetime,
@UserTypeID int,
@UserName varchar(50),
@Password varchar(50),
@SeccretQuestion_ID int,
@Secret_Answer varchar(500),
@IsAccountActive bit
--@Account_Active_Code int --will be implemented later when email func is implemented
)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements. TBL_MM_User_Details
SET NOCOUNT ON;
if(@UserID<>0)
BEGIN
if exists( Select UserName from TBL_MM_User_Info where UserName=@UserName)
BEGIN
update TBL_MM_User_Info
set Password=@Password,
SeccretQuestion_ID=@SeccretQuestion_ID,
Secret_Answer=@Secret_Answer,
IsAccountActive=@IsAccountActive
WHERE UserName=@UserName
UPDATE TBL_MM_User_Details
SET
FirstName=@FirstName,
LastName=@LastName,
Address1=@Address1,
Address2=@Address2,
ZipCode=@ZipCode,
CountryId=@CountryId,
Phone =@Phone,
EmailID=@EmailID,
AlternateEmailID=@AlternateEmailID,
DateOfBirth=@DateOfBirth,
UserTypeID=@UserTypeID
where UserDetailID=@UserDetailID
END
END
ELSE
BEGIN
INSERT INTO TBL_MM_User_Info(UserName,Password,SeccretQuestion_ID,Secret_Answer,IsAccountActive)
VALUES(@UserName,@Password,@SeccretQuestion_ID,@Secret_Answer,@IsAccountActive)
Select @UserID=UserID from TBL_MM_User_Info where UserName=@UserName
INSERT INTO TBL_MM_User_Details (
FirstName,LastName,Address1,Address2,ZipCode,Phone,EmailID,AlternateEmailID,DateOfBirth,
UserTypeID,userID )
VALUES (@FirstName,@LastName,@Address1,@Address2,@ZipCode,@Phone,@EmailID,@AlternateEmailID,
@DateOfBirth,@UserTypeID,@userID
)
END
END
@UserDetailID int=0, --if zero the new record otherwise update
@UserID int=0, --if zero then new record
@FirstName varchar(50),
@LastName varchar(50),
@Address1 varchar(500),
@Address2 varchar(500)=null,
@CityId int,
@StateId int,
@ZipCode nvarchar(50),
@CountryId int,
@Phone varchar(20),
@EmailID nvarchar(50),
@AlternateEmailID nvarchar(50),
@DateOfBirth datetime,
@UserTypeID int,
@UserName varchar(50),
@Password varchar(50),
@SeccretQuestion_ID int,
@Secret_Answer varchar(500),
@IsAccountActive bit
--@Account_Active_Code int --will be implemented later when email func is implemented
)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements. TBL_MM_User_Details
SET NOCOUNT ON;
if(@UserID<>0)
BEGIN
if exists( Select UserName from TBL_MM_User_Info where UserName=@UserName)
BEGIN
update TBL_MM_User_Info
set Password=@Password,
SeccretQuestion_ID=@SeccretQuestion_ID,
Secret_Answer=@Secret_Answer,
IsAccountActive=@IsAccountActive
WHERE UserName=@UserName
UPDATE TBL_MM_User_Details
SET
FirstName=@FirstName,
LastName=@LastName,
Address1=@Address1,
Address2=@Address2,
ZipCode=@ZipCode,
CountryId=@CountryId,
Phone =@Phone,
EmailID=@EmailID,
AlternateEmailID=@AlternateEmailID,
DateOfBirth=@DateOfBirth,
UserTypeID=@UserTypeID
where UserDetailID=@UserDetailID
END
END
ELSE
BEGIN
INSERT INTO TBL_MM_User_Info(UserName,Password,SeccretQuestion_ID,Secret_Answer,IsAccountActive)
VALUES(@UserName,@Password,@SeccretQuestion_ID,@Secret_Answer,@IsAccountActive)
Select @UserID=UserID from TBL_MM_User_Info where UserName=@UserName
INSERT INTO TBL_MM_User_Details (
FirstName,LastName,Address1,Address2,ZipCode,Phone,EmailID,AlternateEmailID,DateOfBirth,
UserTypeID,userID )
VALUES (@FirstName,@LastName,@Address1,@Address2,@ZipCode,@Phone,@EmailID,@AlternateEmailID,
@DateOfBirth,@UserTypeID,@userID
)
END
END