❔ ✅ may someone help me to rewrite this in linq?
var map = new Dictionary<string, List<NotificationModel>>();
foreach (var notification in confirmedNotifications)
{
var to = notification.To
.Except(new HashSet<string> { currentOperator.Name })
.ToList();
if (!to.Any()) continue;
foreach (var user in to)
{
if (map.ContainsKey(user))
map[user].Add(notification);
else
map[user] = new List<NotificationModel> { notification };
}
} var map = new Dictionary<string, List<NotificationModel>>();
foreach (var notification in confirmedNotifications)
{
var to = notification.To
.Except(new HashSet<string> { currentOperator.Name })
.ToList();
if (!to.Any()) continue;
foreach (var user in to)
{
if (map.ContainsKey(user))
map[user].Add(notification);
else
map[user] = new List<NotificationModel> { notification };
}
} I wrote only this:
var test = confirmedNotifications
.Where(notification => notification.To
.Except(new HashSet<string> { currentOperator.Name })
.Any()); var test = confirmedNotifications
.Where(notification => notification.To
.Except(new HashSet<string> { currentOperator.Name })
.Any());