我做了一个应用程序,允许我打开朋友之间的对话,当有人给我发消息时,我收到通知“John给你发新消息”,当对话中的另一个人给我发消息时,会发出新的通知,,,我的问题是我不想发新通知,但我想更新旧通知为ex。像这样“约翰和阿尔弗雷德给你发了一条新信息”..
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(),
SenderName = CurrentUserName
};
entities.Notifications.AddObject(notify);
}
else
{
check.Checked = false;
check.DateTime = DateTime.Now;
}
这里检查是否有用户通知,如果为null则再发新通知“更新通知”