2011-06-17 35 views
0

我做了一个应用程序,允许我打开朋友之间的对话,当有人给我发送消息时,我收到了一条通知“John给你发送了一条新消息”,当对话中的另一个人给我发送了一条消息时, ,,我的问题是,我不想做出新的通知,但我想更新旧的通知为前。像这样的“约翰和Alfred发送新信息” ..如何更新我的通知?

 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,则使其他新的通知“更新通知”

+0

问题是什么? – BrunoLM

回答

1

你的else块表示数据库上存在通知,你可以更新那里的属性。要保存所做的更改,无论是插入还是更新,请拨打method entities.SaveChanges()

+0

我如何更新属性,我已经做了一个方法来保存我从控制器调用它的更改。 –