public bool DeleteUserRolesInApplication(int AppID, string roleIDList, string userNTID)
 {
     try
     {
         sqlconn = new SqlConnection(sqlconnectionstring);
         sqlconn.Open();
         string SP = GlobalConstant.USP_GetApplicationAccessDetails;
         sqlcmd             = new SqlCommand(SP, sqlconn);
         sqlcmd.CommandType = CommandType.StoredProcedure;
         sqlcmd.Parameters.AddWithValue("@AppID", AppID);
         sqlcmd.Parameters.AddWithValue("@RequestType", GlobalConstant.DeleteAccess);
         SqlDataReader  returnLst = sqlcmd.ExecuteReader();
         ConStringAndSP conStrSP  = new ConStringAndSP();
         while (returnLst.Read())
         {
             conStrSP.ConnString      = returnLst["ConnString"].ToString();
             conStrSP.StoredProcedure = returnLst["StoredProcedure"].ToString();
         }
         sqlconn.Close();
         sqlconn = new SqlConnection(conStrSP.ConnString);
         string appSP = conStrSP.StoredProcedure;
         sqlcmd             = new SqlCommand(appSP, sqlconn);
         sqlcmd.CommandType = CommandType.StoredProcedure;
         sqlcmd.Parameters.AddWithValue("@lstRoleID", roleIDList);
         sqlcmd.Parameters.AddWithValue("@CreatedNTID", userNTID);
         sqlconn.Open();
         return((int)sqlcmd.ExecuteScalar() != 1 ? false : true);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
    public int AddUserInApplication(int AppID, int roleID, string userNTID, int ID)
    {
        try
        {
            sqlconn = new SqlConnection(sqlconnectionstring);
            sqlconn.Open();
            string SP = GlobalConstant.USP_GetApplicationAccessDetails;
            sqlcmd             = new SqlCommand(SP, sqlconn);
            sqlcmd.CommandType = CommandType.StoredProcedure;
            sqlcmd.Parameters.AddWithValue("@AppID", AppID);
            sqlcmd.Parameters.AddWithValue("@RequestType", GlobalConstant.AddUser);
            SqlDataReader  returnLst = sqlcmd.ExecuteReader();
            ConStringAndSP conStrSP  = new ConStringAndSP();
            while (returnLst.Read())
            {
                conStrSP.ConnString      = returnLst["ConnString"].ToString();
                conStrSP.StoredProcedure = returnLst["StoredProcedure"].ToString();
            }
            sqlconn.Close();
            sqlconn = new SqlConnection(conStrSP.ConnString);
            string appSP = conStrSP.StoredProcedure;
            sqlcmd             = new SqlCommand(appSP, sqlconn);
            sqlcmd.CommandType = CommandType.StoredProcedure;
            sqlcmd.Parameters.AddWithValue("@NTID", userNTID);
            sqlcmd.Parameters.AddWithValue("@RoleID", roleID);
            sqlcmd.Parameters.AddWithValue("@Operation", 1);
            sqlconn.Open();
            int result = (int)sqlcmd.ExecuteScalar();

            if (result > 0)
            {
                return(UpdateUserAppRoleRequestStatus(ID, Status.Approved, Action.Complete));
            }
            return(result);
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
    /// <summary>
    /// Fetches the LADP details for current login user
    /// </summary>
    /// <returns></returns>
    //public bool GetUserDetailsFromLDAP()
    //{
    //LDAP.LDAP ldapConnection = new LDAP.LDAP();
    //string StampUserId = (Thread.CurrentPrincipal.Identity).Name;
    //int start = StampUserId.IndexOf("\\");
    //StampUserId = StampUserId.Substring(start + 1).ToString();
    //ldapConnection.SetLdapConnection(StampUserId, LDAPConfiguration.GetResourceName("LDAP_CONNECTION"));
    //this.RequestorName = ldapConnection.LastName + ", " + ldapConnection.GivenName;
    //this.RequestorEmail = ldapConnection.Email;
    //return true;
    //}
    /// <summary>
    /// Get Role  from the Application
    /// </summary>
    /// <param name="AppID"></param>
    /// <returns></returns>
    public IEnumerable <ApplicationRoles> GetRole(int AppID, string NewAccess)
    {
        sqlconn = new SqlConnection(sqlconnectionstring);
        sqlconn.Open();
        string SP = GlobalConstant.USP_GetApplicationAccessDetails;

        sqlcmd             = new SqlCommand(SP, sqlconn);
        sqlcmd.CommandType = CommandType.StoredProcedure;
        sqlcmd.Parameters.AddWithValue("@AppID", AppID);
        sqlcmd.Parameters.AddWithValue("@RequestType", NewAccess);
        SqlDataReader  returnLst = sqlcmd.ExecuteReader();
        ConStringAndSP conStrSP  = new ConStringAndSP();

        while (returnLst.Read())
        {
            conStrSP.ConnString      = returnLst["ConnString"].ToString();
            conStrSP.StoredProcedure = returnLst["StoredProcedure"].ToString();
        }
        sqlconn.Close();
        sqlconn = new SqlConnection(conStrSP.ConnString);
        sqlconn.Open();
        string appSP = conStrSP.StoredProcedure;

        sqlcmd             = new SqlCommand(appSP, sqlconn);
        sqlcmd.CommandType = CommandType.StoredProcedure;
        SqlDataReader           appRoleLst = sqlcmd.ExecuteReader();
        List <ApplicationRoles> Lstmenu    = new List <ApplicationRoles>();

        while (appRoleLst.Read())
        {
            ApplicationRoles m = new ApplicationRoles();
            m.RoleID   = (int)appRoleLst["RoleID"];
            m.AppID    = AppID;
            m.RoleName = appRoleLst["RoleName"].ToString();
            Lstmenu.Add(m);
        }
        sqlconn.Close();
        return(Lstmenu);
    }
    public List <int> GetUserAppRoleRequestData(int AppID, string NTID)
    {
        sqlconn = new SqlConnection(sqlconnectionstring);
        sqlconn.Open();
        string SP = GlobalConstant.USP_GetApplicationAccessDetails;

        sqlcmd             = new SqlCommand(SP, sqlconn);
        sqlcmd.CommandType = CommandType.StoredProcedure;
        sqlcmd.Parameters.AddWithValue("@AppID", AppID);
        sqlcmd.Parameters.AddWithValue("@RequestType", GlobalConstant.ModifyAccess);
        SqlDataReader  returnLst = sqlcmd.ExecuteReader();
        ConStringAndSP conStrSP  = new ConStringAndSP();

        while (returnLst.Read())
        {
            conStrSP.ConnString      = returnLst["ConnString"].ToString();
            conStrSP.StoredProcedure = returnLst["StoredProcedure"].ToString();
        }
        sqlconn.Close();
        sqlconn = new SqlConnection(conStrSP.ConnString);
        sqlconn.Open();
        string appSP = conStrSP.StoredProcedure;

        sqlcmd             = new SqlCommand(appSP, sqlconn);
        sqlcmd.CommandType = CommandType.StoredProcedure;
        sqlcmd.Parameters.AddWithValue("@UserNTID", NTID);
        SqlDataReader appRoleLst = sqlcmd.ExecuteReader();
        List <int>    Lstmenu    = new List <int>();

        while (appRoleLst.Read())
        {
            int m;
            m = (int)appRoleLst["RoleID"];
            Lstmenu.Add(m);
        }

        return(Lstmenu);
    }