rahul singh rathour

rahul singh rathour

  • 1.6k
  • 108
  • 1.3k

Sql Serever and SMTP Issue in C#

Jan 15 2024 11:36 AM

problem1: If multiple agents are sending emails to multiple users at the same time, then the email of one agent is getting inserted into the other. for exp: Agent Amit send email to user alex and agent shiva send email to user aman then after send email only agent shiva logs [Which Agent has sent the email to which user] will be created for both user alex and aman. Hope you will understand.

----SQL Procedure     
CREATE PROCEDURE [dbo].[Get_SendEmailSendTOPAX_CS_V1]           
           
@PAXUID Varchar(250),                            
@AgentName Varchar(250)            
AS          
BEGIN        
 SET NOCOUNT ON;     
 SET TRANSACTION ISOLATION LEVEL SERIALIZABLE  

  BEGIN TRANSACTION;            
          
  if EXISTS(select 1 from [dbo].[tbl_agent] where agentgalaxyname=@AgentName AND Isactive=1)                             
BEGIn          
         
IF OBJECT_ID('#SendEmailPAX_CS', 'U') IS NOT NULL  
  DROP TABLE #SendEmailPAX_CS;   
 
--DROP TABLE IF EXISTS dbo.#SendEmailPAX_CS;  
          
Create table #SendEmailPAX_CS          
(          
PAXUID Varchar(250),          
AgentName Varchar(250),             
BookingID INT,         
BookingTypeID INT,        
AgentID INT ,          
Gateway_Type  nvarchar(250),                          
Gateway_Type_Name  nvarchar(250),                          
Gateway_Email nvarchar(250),                            
AirlineName nvarchar(250),                            
Gateway nvarchar(250),                                              
TollFreeNumber nvarchar(250),                            
Subject_TFN varchar(50),                            
ConsentURL_ varchar(50) ,                             
GatewayID INT ,                            
PAX_Email varchar(50),                            
PAXEmailSend_ID INT,                            
EMail_Subject varchar(250),                                         
FinalGateway varchar(250)          
)          
          
INSERt INTO #SendEmailPAX_CS (PAXUID,AgentName)          
SELeCT @PAXUID,@AgentName          
          
--For AgentID          
UPDATE SEP             
  SET SEP.AgentID = TA.AgentID           
from #SendEmailPAX_CS SEP          
  INNER JOIN tbl_Agent TA          
    ON TA.AgentGalaxyName=@AgentName          
          
--For BookingID          
 UPDATE SEP             
  SET SEP.BookingID = TPD.PassengerDetailID , BookingTypeID=TPD.BookingTypeID        
from #SendEmailPAX_CS SEP          
  INNER JOIN tbl_PassengerDetail TPD          
    ON TPD.PassengerUID=@PAXUID          
          
 --Charging gateway Type           
 UPDATE #SendEmailPAX_CS          
SET Gateway_Type = APD.Gateway_Type,Gateway_Type_Name=APD.Gateway_Type_Name,PAX_Email=APD.PAX_Email,          
FinalGateway=(          
case           
when #SendEmailPAX_CS.Gateway_Type='Everyware' THEN 'SFC'         
when #SendEmailPAX_CS.BookingTypeID in (4,1023,1025)  THEN 'Cancellation'          
ELSE APD.Gateway_Type  end)          
FROM (SELECT TOP 1 SUBSTRING(gateway,0, CHARINDEX('-',gateway)) [Gateway_Type],Gateway [Gateway_Type_Name] ,PAX_Email,PNR FROM [dbo].tbl_AuthorizePaymentDetails           
where pnr=(select cast(BookingID as varchar) from #SendEmailPAX_CS where PAXUID=@PAXUID) ORDER BY ID DESC) AS APD          
WHERE #SendEmailPAX_CS.BookingID = APD.PNR;          
          
          
--GET Gateway Details          
UPDATE #SendEmailPAX_CS          
SEt Gateway_Email=MGT.Gateway_Email,Gateway=MGT.Gateway,TollFreeNumber=MGT.TollFreeNumber,AirlineName=MGT.AirlineName,Subject_TFN=MGT.Subject_TFN,          
ConsentURL_=MGT.ConsentURL          
from (select top 1 Gateway_Email [Gateway_Email],TravelName [Gateway], AirlineName [AirlineName],                                              
REPLACE(REPLACE(TollFreeNumber, CHAR(13), ''), CHAR(10), '') [TollFreeNumber],                                  
REPLACE(REPLACE(Subject_TFN, CHAR(13), ''), CHAR(10), '')[Subject_TFN],ConsentURL[ConsentURL]                             
 from [dbo].tbl_ManageGateway where Gateway_type=(Select top 1 FinalGateway from #SendEmailPAX_CS where PAXUID=@PAXUID)) AS MGT          
                            
          
Select PAXUID,AgentName,BookingID,BookingTypeID,AgentID,Gateway_Type,Gateway_Type_Name,                          
Gateway_Email,AirlineName,Gateway,                                              
TollFreeNumber,Subject_TFN,ConsentURL_,                 
GatewayID,PAX_Email ,                            
PAXEmailSend_ID ,                            
EMail_Subject ,                                         
FinalGateway  from #SendEmailPAX_CS  where  PAXUID=@PAXUID        
          
DROP TABLE #SendEmailPAX_CS          
END              
COMMIT TRANSACTION;            
          
END

------------------procedure 2

CREATE procedure [dbo].[InsertCaseHistory_SendEmail]  
@AgentID varchar(250),  
@Query  nvarchar(MAX),   
@PassengerID  varchar(250)  
AS  
 
BEGIn  
SET NOCOUNT ON;  
 
INSERT INTO dbo.tbl_CaseHistory (AgentID,Query,PassengerID,CreationDate,isactive)  
                   VALUES (@AgentID, @Query, @PassengerID,GETDATE(),1)   
END  
 

-----------------------

C# Code

 

 

 

 


Answers (2)