Пример #1
0
        public static bool AddDenyRoleForUser(Guid userid, List <Guid> roles)
        {
            bool isSucess = false;

            Sys_NguoiDungQuyenRepository repository = new Sys_NguoiDungQuyenRepository();

            foreach (Guid g in roles)
            {
                Sys_NguoiDungQuyen userRole = new Sys_NguoiDungQuyen();
                userRole.RoleId = g;
                userRole.UserId = userid;
                repository.Add(userRole);
            }
            repository.SubmitChanges();
            isSucess = true;

            return(isSucess);
        }
Пример #2
0
        public static bool RemoveDenyRoleForUser(Guid userid, List <Guid> roles)
        {
            bool isSucess = false;

            Sys_NguoiDungQuyenRepository repository = new Sys_NguoiDungQuyenRepository();

            foreach (Guid g in roles)
            {
                Sys_NguoiDungQuyen userRole = repository.GetTable().Where(x => x.UserId == userid && x.RoleId == g).FirstOrDefault();
                if (userRole != null)
                {
                    repository.Delete(userRole.ID);
                }
            }
            repository.SubmitChanges();
            isSucess = true;
            return(isSucess);
        }
Пример #3
0
        public static bool AddPermissionToUser(Guid userId, string userName, List <string> grantPermissions, List <Guid> denyPermission)
        {
            bool isSuccess = false;

            try
            {
                Roles.AddUserToRoles(userName, grantPermissions.ToArray());
                Sys_NguoiDungQuyenRepository userPermissionRepository = new Sys_NguoiDungQuyenRepository();
                foreach (Guid guid in denyPermission)
                {
                    Sys_NguoiDungQuyen userPermission = new Sys_NguoiDungQuyen();
                    userPermission.RoleId = guid;
                    userPermission.UserId = userId;
                    userPermissionRepository.Add(userPermission);
                }
                userPermissionRepository.SubmitChanges();
                isSuccess = true;
            }
            catch
            {
            }

            return(isSuccess);
        }