public Guid CreateSession(UserSessionBO obj)
        {
            DBEgine dbEngine = new DBEgine();
            try
            {
                dbEngine.DBOpen();
                SqlParameter[] parms = new SqlParameter[3];

                SqlParameter p1 = new SqlParameter();
                p1.ParameterName = "UserId";
                p1.SqlDbType = SqlDbType.Int;
                p1.Value = obj.UserID;
                parms[0] = p1;

                SqlParameter p2 = new SqlParameter();
                p2.ParameterName = "LanguageID";
                p2.SqlDbType = SqlDbType.Int;
                p2.Value = obj.LanguageID;
                parms[1] = p2;

                SqlParameter p3 = new SqlParameter();
                p3.ParameterName = "UserSessionID";
                p3.SqlDbType = SqlDbType.UniqueIdentifier;
                p3.Direction = ParameterDirection.Output;
                parms[2] = p3;

                dbEngine.ExecNonQueryStoredProc("UM_CreateUserSession", parms);

                return (Guid)p3.Value;

            }
            catch
            {
                throw;
            }
            finally
            {
                dbEngine.DBClose();
            }
        }
        public UserSessionBO GetActiveUserSessionBySessionID(UserSessionBO obj)
        {
            DBEgine dbEngine = new DBEgine();
            try
            {
                UserSessionBO us = null;

                dbEngine.DBOpen();
                SqlParameter[] parms = new SqlParameter[1];

                SqlParameter p1 = new SqlParameter();
                p1.ParameterName = "UserSessionID";
                p1.SqlDbType = SqlDbType.UniqueIdentifier;
                p1.Value = obj.UserSessionID;
                parms[0] = p1;

                SqlDataReader sqlDr = dbEngine.ExecuteReader("UM_GetActiveUserSessionBySessionID", parms);

                if (sqlDr != null && sqlDr.HasRows)
                {
                    us = new UserSessionBO();
                    while (sqlDr.Read())
                    {
                        us = Fill(sqlDr);
                        UserSessionLastAccessUpdate(us);
                    }
                }

                return us;
            }
            catch
            {
                throw;
            }
            finally
            {
                dbEngine.DBClose();
            }
        }
        private UserSessionBO Fill(SqlDataReader dr)
        {
            var us = new UserSessionBO();
            us.UserSessionID = dr.GetGuid(dr.GetOrdinal("UserSessionID"));
            us.UserID = dr.GetInt32(dr.GetOrdinal("UserID"));
            us.CreatedOn = dr.GetDateTime(dr.GetOrdinal("CreatedOn"));
            us.LastAccessOn = dr.GetDateTime(dr.GetOrdinal("LastAccessOn"));
            us.IsLogout = dr.GetBoolean(dr.GetOrdinal("IsLogout"));
            us.LogoutBy = dr.GetInt32(dr.GetOrdinal("LogoutBy"));

            if (!dr.IsDBNull(dr.GetOrdinal("LogoutTime")))
            {
                us.LogoutTime = dr.GetDateTime(dr.GetOrdinal("LogoutTime"));
            }

            if (!dr.IsDBNull(dr.GetOrdinal("Remark")))
            {
                us.Remark = dr.GetValue(dr.GetOrdinal("Remark")).ToString();
            }

            return us;
        }
        public void UsersessionLogoutByUserID(DBEgine dbEngine, UserSessionBO userSession)
        {
            try
            {

                SqlParameter[] parms = new SqlParameter[3];

                SqlParameter p1 = new SqlParameter();
                p1.ParameterName = "UserSessionID";
                p1.SqlDbType = SqlDbType.UniqueIdentifier;
                p1.Value = userSession.UserSessionID;
                parms[0] = p1;

                SqlParameter p2 = new SqlParameter();
                p2.ParameterName = "UserID";
                p2.SqlDbType = SqlDbType.Int;
                p2.Value = userSession.UserID;
                parms[1] = p2;

                SqlParameter p3 = new SqlParameter();
                p3.ParameterName = "Remark";
                p3.SqlDbType = SqlDbType.VarChar;
                p3.Value = userSession.Remark;
                parms[2] = p3;

                dbEngine.ExecNonQueryStoredProc("UM_UsersessionLogoutByUserID", parms);

            }
            catch
            {
                throw;
            }
        }
        public void UsersessionLogoutByUserID(UserSessionBO obj)
        {
            DBEgine dbEngine = new DBEgine();
            try
            {

                dbEngine.DBOpen();
                SqlParameter[] parms = new SqlParameter[3];

                SqlParameter p1 = new SqlParameter();
                p1.ParameterName = "UserSessionID";
                p1.SqlDbType = SqlDbType.UniqueIdentifier;
                p1.Value = obj.UserSessionID;
                parms[0] = p1;

                SqlParameter p2 = new SqlParameter();
                p2.ParameterName = "UserID";
                p2.SqlDbType = SqlDbType.Int;
                p2.Value = obj.UserID;
                parms[1] = p2;

                SqlParameter p3 = new SqlParameter();
                p3.ParameterName = "Remark";
                p3.SqlDbType = SqlDbType.VarChar;
                p3.Value = obj.Remark;
                parms[2] = p3;

                dbEngine.ExecNonQueryStoredProc("UM_UsersessionLogoutByUserID", parms);

            }
            catch
            {
                throw;
            }
            finally
            {
                dbEngine.DBClose();
            }
        }
        public void UserSessionLastAccessUpdate(UserSessionBO obj)
        {
            DBEgine dbEngine = new DBEgine();
            try
            {

                dbEngine.DBOpen();
                SqlParameter[] parms = new SqlParameter[1];

                SqlParameter p1 = new SqlParameter();
                p1.ParameterName = "UserSessionID";
                p1.SqlDbType = SqlDbType.UniqueIdentifier;
                p1.Value = obj.UserSessionID;
                parms[0] = p1;

                dbEngine.ExecNonQueryStoredProc("UM_UserSessionLastAccessUpdate", parms);

            }
            catch
            {
                throw;
            }
            finally
            {
                dbEngine.DBClose();
            }
        }
 public static void Replace(UserSessionBO sessionHandler)
 {
 }
        public List<UserSessionBO> SearchUserSession(int BranchId, DateTime FromDate, DateTime ToDate, int LoginStatus)
        {
            List<UserSessionBO> listUserSessionDetail = new List<UserSessionBO>();
            DBEgine dbEngine = new DBEgine();
            try
            {

                dbEngine.DBOpen();

                SqlParameter[] arrSqlParam = new SqlParameter[4];

                SqlParameter pBranchID = new SqlParameter();
                pBranchID.ParameterName = "@branchId";
                pBranchID.SqlDbType = SqlDbType.Int;
                pBranchID.Value = BranchId;
                arrSqlParam[0] = pBranchID;

                SqlParameter pFromDate = new SqlParameter();
                pFromDate.ParameterName = "@FromDate";
                pFromDate.SqlDbType = SqlDbType.Date;
                pFromDate.Value = FromDate;
                arrSqlParam[1] = pFromDate;

                SqlParameter pToDate = new SqlParameter();
                pToDate.ParameterName = "@ToDate";
                pToDate.SqlDbType = SqlDbType.Date;
                pToDate.Value = ToDate;
                arrSqlParam[2] = pToDate;

                SqlParameter pLoginStatus = new SqlParameter();
                pLoginStatus.ParameterName = "@loginStatus";
                pLoginStatus.SqlDbType = SqlDbType.Int;
                pLoginStatus.Value = LoginStatus;
                arrSqlParam[3] = pLoginStatus;

                SqlDataReader sqlDataReader = dbEngine.ExecuteReader("UM_SearchUserSessionDetails", arrSqlParam);

                while (sqlDataReader.Read())
                {
                    UserSessionBO userSessionDetail = new UserSessionBO();

                    if (!sqlDataReader.IsDBNull(sqlDataReader.GetOrdinal("UserSessionID")))
                    {
                        userSessionDetail.UserSessionID = sqlDataReader.GetGuid(sqlDataReader.GetOrdinal("UserSessionID"));

                    }

                    if (!sqlDataReader.IsDBNull(sqlDataReader.GetOrdinal("UserID")))
                    {
                        userSessionDetail.UserID = sqlDataReader.GetInt32(sqlDataReader.GetOrdinal("UserID"));

                    }

                    if (!sqlDataReader.IsDBNull(sqlDataReader.GetOrdinal("UserName")))
                    {
                        userSessionDetail.UserName = sqlDataReader.GetString(sqlDataReader.GetOrdinal("UserName"));

                    }
                    if (!sqlDataReader.IsDBNull(sqlDataReader.GetOrdinal("FullName")))
                    {
                        userSessionDetail.FullName = sqlDataReader.GetString(sqlDataReader.GetOrdinal("FullName"));

                    }
                    if (!sqlDataReader.IsDBNull(sqlDataReader.GetOrdinal("BranchID")))
                    {
                        userSessionDetail.BranchID = sqlDataReader.GetInt32(sqlDataReader.GetOrdinal("BranchID"));

                    }

                    if (!sqlDataReader.IsDBNull(sqlDataReader.GetOrdinal("BranchName")))
                    {
                        userSessionDetail.BranchName = sqlDataReader.GetString(sqlDataReader.GetOrdinal("BranchName"));

                    }

                    if (!sqlDataReader.IsDBNull(sqlDataReader.GetOrdinal("CreatedOn")))
                    {
                        userSessionDetail.CreatedOn = sqlDataReader.GetDateTime(sqlDataReader.GetOrdinal("CreatedOn"));

                    }
                    if (!sqlDataReader.IsDBNull(sqlDataReader.GetOrdinal("LastAccessOn")))
                    {
                        userSessionDetail.LastAccessOn = sqlDataReader.GetDateTime(sqlDataReader.GetOrdinal("LastAccessOn"));

                    }
                    if (!sqlDataReader.IsDBNull(sqlDataReader.GetOrdinal("IsLogout")))
                    {
                        userSessionDetail.IsLogout = sqlDataReader.GetBoolean(sqlDataReader.GetOrdinal("IsLogout"));

                    }
                    if (!sqlDataReader.IsDBNull(sqlDataReader.GetOrdinal("LogoutType")))
                    {
                        userSessionDetail.LogoutType = sqlDataReader.GetInt32(sqlDataReader.GetOrdinal("LogoutType"));

                    }
                    if (!sqlDataReader.IsDBNull(sqlDataReader.GetOrdinal("LogoutBy")))
                    {
                        userSessionDetail.LogoutBy = sqlDataReader.GetInt32(sqlDataReader.GetOrdinal("LogoutBy"));

                    }
                    if (!sqlDataReader.IsDBNull(sqlDataReader.GetOrdinal("LogoutTime")))
                    {
                        userSessionDetail.LogoutTime = sqlDataReader.GetDateTime(sqlDataReader.GetOrdinal("LogoutTime"));

                    }
                    if (!sqlDataReader.IsDBNull(sqlDataReader.GetOrdinal("Remark")))
                    {
                        userSessionDetail.Remark = sqlDataReader.GetString(sqlDataReader.GetOrdinal("Remark"));

                    }

                    listUserSessionDetail.Add(userSessionDetail);

                }

            }
            catch
            {
                throw;
            }
            finally
            {
                dbEngine.DBClose();
            }
            return listUserSessionDetail;
        }