Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
Node is saved as draft in My Content >> Draft
  • Nudge in API

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 59
    Comment on it

    While writing API services you need to understand what nudge in that actually means if you come across that particular word.

     

    Nudge is nothing but a general message that we sent to another user or group of users.

     

    We can send single nudge or multiple nudge to the persons.

     

    This is my stored procedure that will  display the nudge details to the particular employee.

     

    ALTER PROC [dbo].[uspGetNudgesDetails]
    @AccessToken VARCHAR(50),
    @BeaconID VARCHAR(50)=NULL
    AS
    
    BEGIN
    
    	DECLARE @CompanyID BIGINT =0
    	DECLARE @TargetUserID BIGINT=0
    	DECLARE @UserName varchar(50)
    -- Get user and company
    
    	SELECT @UserName=[FirstName] + ' ' + LastName, 
    			@TargetUserID=[ID],
    			@CompanyID=[CompanyID]
    		FROM [User] WHERE AccessToken=@AccessToken
    
    
    		----DECLARE @CreatedDate AS DATETIME = GETDATE()
    		----DECLARE @ExpiryDate AS DATETIME = (SELECT DATEADD(DAY, @DaysTillExpire, @CreatedDate))
    		----SET @ExpiryDate = (SELECT DATEADD(HOUR, @HoursTillExpire, @ExpiryDate))
    
    		UPDATE NUDGE
    		SET DaysTillExpire = CASE  WHEN DATEDIFF(day, GETDATE(), ExpiryDate) < 0 THEN 0
    									ELSE DATEDIFF(day, GETDATE(), ExpiryDate)
    							END				
    		,
    		HoursTillExpire = CASE  WHEN DATEDIFF( hour, GETDATE(), ExpiryDate) < 0 THEN 0
    									ELSE DATEDIFF(day, GETDATE(), ExpiryDate)
    							END				
    
    		,
    		IsExpired = CASE WHEN DATEDIFF(day, GETDATE(), ExpiryDate) < 0 AND DATEDIFF( hour, GETDATE(), ExpiryDate) < 0 THEN 1
    							ELSE 0
    							END
    -- For general message with no location
    
    	SELECT N.[ID],
    		N.[Message],
    		@BeaconID as [BeaconID],		
    		N.[LocationID],
    		NULL AS Location,
    		N.[TargetUserID],
    		@UserName as [TargetUser],	
    		N.[IsCompleted],
    		N.[IsDelivered],
    		N.[IsExpired],
    		N.[IsDeleted],
    		N.[Url],		
    		N.[DaysTillExpire],
    		N.[HoursTillExpire],
    		--DATEDIFF( day, GETDATE(), N.ExpiryDate ) AS DaysTillExpire,
    		--DATEDIFF( hour, GETDATE(), N.ExpiryDate ) AS HoursTillExpire,
    		(U.[FirstName] + ' ' + U.[LastName]) AS [CreatedBy],
    		CONVERT(VARCHAR(20), N.[CreatedDate], 103) as [CreatedDate],
    		@CompanyID as [CompanyID]
    		
    		FROM [NUDGE] AS N 
    				INNER JOIN  [User] AS U ON N.[CreatedBy]=U.[ID] 
    		WHERE N.[LocationID]=0 
    				AND N.[TargetUserID]=@TargetUserID
    				AND N.[IsDeleted]=0 
    				AND N.[IsExpired]=0 
    				AND N.[IsCompleted]=0 
    
    	UNION
    
    -- For location dependent messages
    
    	SELECT  N.[ID],
    		N.[Message],
    		@BeaconID as [BeaconID],
    		N.[LocationID],
    		L.[Location],
    		N.[TargetUserID],
    		@UserName as [TargetUser],	
    		N.[IsCompleted],
    		N.[IsDelivered],
    		N.[IsExpired],
    		N.[IsDeleted],		
    		N.[Url],		
    		N.[DaysTillExpire],
    		N.[HoursTillExpire],
    		--DATEDIFF( day, GETDATE(), N.ExpiryDate ) AS DaysTillExpire,
    		--DATEDIFF( hour, GETDATE(), N.ExpiryDate ) AS HoursTillExpire,	
    		(U.[FirstName] + ' ' + U.[LastName]) AS [CreatedBy],
    		CONVERT(VARCHAR(20), N.[CreatedDate], 103) as [CreatedDate],
    		@CompanyID as [CompanyID]
    		
    		
    		FROM [NUDGE] AS N 
    			INNER JOIN  [User] AS U ON N.[CreatedBy]=U.[ID] 
    			INNER JOIN [LOCATION] AS L ON L.[ID]=N.[LocationID] 
    		WHERE N.[LocationID]=(SELECT [LocationID] FROM [Location] WHERE [BeaconUUID]=@BeaconID and [CompanyID]=@CompanyID)
    			AND N.[TargetUserID]=@TargetUserID
    			AND N.[IsDeleted]=0 
    			AND N.[IsExpired]=0 
    			AND N.[IsCompleted]=0 
    END
    

     

    This will show all the messages meant for the particular user or employee.

     

    I have made service to call that particular stored procedure.

     

     public NudgeListDetailsResponse GetEmployeeNudges(string accessToken)
            {
                NudgeListDetailsResponse nudgeResponse = new NudgeListDetailsResponse();
                List<NudgeListRequest> nudgeDetailsList = new List<NudgeListRequest>();
                nudgeResponse.data = new List<NudgeListRequest>();
                try
                {
                    SqlDataReader reader = null;
                    using (SqlConnection sqlConnection = new SqlConnection(ConnectionString))
                    {
                        if (sqlConnection.State == ConnectionState.Closed)
                        {
                            sqlConnection.Open();
                        }
                        SqlCommand cmd = new SqlCommand("uspGetNudges", sqlConnection);
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.Parameters.Add("@AccessToken", SqlDbType.VarChar, 100).Value = accessToken;
                        reader = cmd.ExecuteReader();
                        if (reader.HasRows)
                        {
                            while (reader.Read())
                            {
                                nudgeDetailsList.Add(new NudgeListRequest
                                {
                                    ID = reader["ID"] != null ? !string.IsNullOrEmpty(Convert.ToString(reader["ID"])) ? Convert.ToInt32(Convert.ToString(reader["ID"]).Trim()) : 0 : 0,
                                    Message = reader["Message"] != null ? Convert.ToString(reader["Message"]).Trim() : string.Empty,
                                    TargetUser = reader["TargetUser"] != null ? Convert.ToString(reader["TargetUser"]).Trim() : string.Empty,
                                    CreatedBy = reader["CreatedBy"] != null ? Convert.ToString(reader["CreatedBy"]).Trim() : string.Empty,
                                    CreatedDate = reader["CreatedDate"] != null ? Convert.ToString(reader["CreatedDate"]).Trim() : string.Empty,
                                    Company = reader["Company"] != null ? Convert.ToString(reader["Company"]).Trim() : string.Empty,
                                    Location = reader["Location"] != null ? Convert.ToString(reader["Location"]).Trim() : string.Empty
                                });
                            }
                        }
                        else
                        {
                            nudgeResponse.Message = "No Nudge Found";
                        }
                    }
                    nudgeResponse.Status = true;
                }
                catch (SqlException ex)
                {
                    Logger.LogException(ex);
                    nudgeResponse.Message = ex.Message;
                    nudgeResponse.Status = false;
                }
                nudgeResponse.data = nudgeDetailsList;
                return nudgeResponse;
            }
    

     

     

     

    .net

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: