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); }
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); }
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); }