i made an application that allow me to open conversation between friends, when someone send me a message i got a notification "John send you a new message" and when another person in the conversation send me a message a new notification is made ,,, my problem is that i don't want to make a new notification but i want to update the old notification to be for ex. like this " John and Alfred send you a new message"..
var user = users.Where(x => x != CurrentUserId);
foreach (var item in user)
{
var check = entities.Notifications.SingleOrDefault(i => (i.NotificationForId == id
&& i.NotificationForType == IdType && i.UserId == item));
if (check == null)
{
Notification notify = new Notification()
{
NotificationForId = id,
NotificationForType = IdType,
DateTime = DateTime.Now,
Message = GenerateMessage(),
UserId = item,
SenderID = CurrentUserId.ToString(),
Sende开发者_开发知识库rName = CurrentUserName
};
entities.Notifications.AddObject(notify);
}
else
{
check.Checked = false;
check.DateTime = DateTime.Now;
}
here it check if there are any notification for a user , if null then make a new notification else " Update the notification "
Your else block indicates the notification exists on the database, you can update the properties there. To save the changes made, both for insert and update call the method entities.SaveChanges()
精彩评论