本文整理匯總了C#中Service.List.Intersect方法的典型用法代碼示例。如果您正苦於以下問題:C# List.Intersect方法的具體用法?C# List.Intersect怎麽用?C# List.Intersect使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Service.List
的用法示例。
在下文中一共展示了List.Intersect方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: RemoveUsersFromRoles
private void RemoveUsersFromRoles(List<NhUserAccount> users, List<Role> roles)
{
if (users == null || users.Count == 0 || roles == null || roles.Count == 0)
return;
StringBuilder message=new StringBuilder();
using (var scope = new UnitOfWorkScope())
{
foreach (var userEntity in users)
{
if (userEntity.Roles != null && userEntity.Roles.Any())
{
int oldCount = userEntity.Roles.Count;
var matchedRoles = roles.Intersect(userEntity.Roles);
message.AppendFormat("Role(s) {0} are removed from user {1}.", string.Join(",", matchedRoles.Select(x => x.Name)), userEntity.Username);
foreach (var matchedRole in matchedRoles)
userEntity.Roles.Remove(matchedRole);
if (oldCount != userEntity.Roles.Count)
{
_userRepository.Update(userEntity);
}
}
}
scope.Commit();
}
if (message.Length > 0)
{
ActivityLog item = new ActivityLog(ActivityType.RemoveUserFromRole.ToString(), message.ToString());
_activityLogService.Add(item);
}
}