示例#1
0
 private void SaveOrUpdateRoleUser(Guid userId, IList<string> roleCodes)
 {
     var userInContext = NpcContext.CurrentUser;
     if (roleCodes == null || !roleCodes.Any())
         return;
     var roleUserRepository = new RoleUserRepository();
     var roleRepository = new RoleRepository();
     var roleUser = roleUserRepository.GetRoleUserByUserId(userId) ?? new RoleUser();
     roleUser.Roles.Clear();
     roleUser.UserId = userId;
     var roles = roleRepository.GetRolesByCodes(roleCodes, userInContext.Unit.Id);
     roles.ToList().ForEach(role => roleUser.Roles.Add(role));
     roleUserRepository.Save(roleUser);
 }