Exemplo n.º 1
0
        public ReturnUserPermission ListAllControllerName_PermissionByUserID(int userID)
        {
            List <UserPermission> lstUserPermission = null;
            UserPermission        userPermission    = null;
            ReturnUserPermission  returnUserMenu    = new ReturnUserPermission();

            try
            {
                using (SqlConnection sqlConnection = ConnectSQLCommon.CreateAndOpenSqlConnection())
                {
                    using (SqlCommand cmd = new SqlCommand("", sqlConnection))
                    {
                        //cmd.Connection = _sqlConnection;
                        cmd.CommandText = "sp_tMenu_ListAllControllerName_PermissionByUserID";
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.Parameters.Add(new SqlParameter("@UserID", SqlDbType.Int)).Value = userID;

                        using (SqlDataReader sqlDr = ConnectSQLCommon.ExecuteDataReader(cmd, sqlConnection))
                        {
                            if (sqlDr.HasRows)
                            {
                                lstUserPermission = new List <UserPermission>();
                                while (sqlDr.Read())
                                {
                                    userPermission                = new UserPermission();
                                    userPermission.RoleID         = int.Parse(sqlDr["RoleID"].ToString());
                                    userPermission.MenuID         = int.Parse(sqlDr["MenuID"].ToString());
                                    userPermission.Permission     = sqlDr["Permission"].ToString();
                                    userPermission.ControllerName = sqlDr["ControllerName"].ToString();
                                    lstUserPermission.Add(userPermission);
                                }
                                returnUserMenu.Code              = "00";
                                returnUserMenu.Message           = "Lấy dữ liệu thành công.";
                                returnUserMenu.lstUserPermission = lstUserPermission;
                            }
                            else
                            {
                                returnUserMenu.Code              = "01";
                                returnUserMenu.Message           = "Không tồn tại bản ghi nào.";
                                returnUserMenu.Total             = 0;
                                returnUserMenu.lstUserPermission = null;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                returnUserMenu.Code              = "99";
                returnUserMenu.Message           = "Lỗi xử lý dữ liệu: " + ex.ToString();
                returnUserMenu.Total             = 0;
                returnUserMenu.lstUserPermission = null;
                mylog4net.Error("", ex);
            }
            return(returnUserMenu);
        }
Exemplo n.º 2
0
        public static PermisionControllerVM getPermisionControllerViewModel(string controllerName, ReturnUserPermission userPermission)
        {
            PermisionControllerVM permisionControllerViewModel = new PermisionControllerVM();

            permisionControllerViewModel.Code           = "00";
            permisionControllerViewModel.isAllow_View   = false;
            permisionControllerViewModel.isAllow_Add    = false;
            permisionControllerViewModel.isAllow_Edit   = false;
            permisionControllerViewModel.isAllow_Delete = false;
            permisionControllerViewModel.isAllow_Check  = false;
            if (userPermission == null)
            {
                return(permisionControllerViewModel);
            }

            try
            {
                permisionControllerViewModel.isAllow_View   = userPermission.lstUserPermission.Find(o => (o.ControllerName == controllerName) && (o.Permission.Contains(SMCommon.View))) != null ? true : false;
                permisionControllerViewModel.isAllow_Add    = userPermission.lstUserPermission.Find(o => (o.ControllerName == controllerName) && (o.Permission.Contains(SMCommon.Add))) != null ? true : false;
                permisionControllerViewModel.isAllow_Edit   = userPermission.lstUserPermission.Find(o => (o.ControllerName == controllerName) && (o.Permission.Contains(SMCommon.Edit))) != null ? true : false;
                permisionControllerViewModel.isAllow_Delete = userPermission.lstUserPermission.Find(o => (o.ControllerName == controllerName) && (o.Permission.Contains(SMCommon.Delete))) != null ? true : false;
                permisionControllerViewModel.isAllow_Check  = userPermission.lstUserPermission.Find(o => (o.ControllerName == controllerName) && (o.Permission.Contains(SMCommon.Check))) != null ? true : false;
            }
            catch (Exception ex)
            {
                permisionControllerViewModel.Code           = "99";
                permisionControllerViewModel.Message        = "Lỗi kiểm tra quyền/Error while checking permission! : " + ex.ToString();
                permisionControllerViewModel.isAllow_View   = false;
                permisionControllerViewModel.isAllow_Add    = false;
                permisionControllerViewModel.isAllow_Edit   = false;
                permisionControllerViewModel.isAllow_Delete = false;
                permisionControllerViewModel.isAllow_Check  = false;
            }
            return(permisionControllerViewModel);
        }
Exemplo n.º 3
0
        public static bool CheckUserPermission(string controllerName, string checkPermission, ReturnUserPermission userPermission)
        {
            if (userPermission == null)
            {
                return(false);
            }
            UserPermission x = userPermission.lstUserPermission.Find(o => (o.ControllerName == controllerName) && (o.Permission.Contains(checkPermission)));

            if (x != null)
            {
                return(true);
            }
            return(false);
        }