List<Comment> StreamItemComments = objStreamItem.GetComments();
…
foreach (Comment Item in StreamItemComments)
{
if (ClientUser.UserName != Item.Sender)
{
Notification notificationObj = new Notification
{
Sender = ClientUser.UserName,
Recipient = Item.Sender,
Value = "whatever value here",
TrackBack = "",
IsRead = false
};
notificationObj.Add();
}
}
What if there are two ‘username’ in List in Item.Sender. I’d like to send a notification once to the user. Here if there are duplicate usernames it will send two notifications because i am not filtering out duplicate Item.Senders from the list in StreamItemComments.
Consider writing a query to state your intentions. You want the distinct senders of the item comments, but only where the sender is not the client user. Sounds like a query, does it not?
You can then use this query to build your notifications
You could also fit this object construction into the query, as well, but with your
.Add()invocation on each object, I left it out of the query. It wouldn’t be difficult to incorporate, although you’d still need to loop over the output and invoke.Add()for each result.