public ActionResult ReadMsg(string id) { int msgid; int unread; if (int.TryParse(id, out msgid)) { string username = User.Identity.Name; Message message = _udb.Messages.Find(msgid); unread = _udb.Messages.Count(m => m.Recipient == username && !m.IsRead && !m.IsRecipientDelete); if (message == null || message.IsRecipientDelete || !message.Recipient.Equals(User.Identity.Name, StringComparison.OrdinalIgnoreCase)) { return(NotFound()); } if (!message.IsRead) { message.IsRead = true; unread--; _udb.SaveChanges(); } _cache.Set("unreadmsg" + username.ToLower(), unread); return(Json(new { MsgId = message.MsgId, MsgTitle = message.MsgTitle, Sender = message.Sender, Recipient = message.Recipient, MsgDate = message.MsgDate, MsgContent = message.MsgContent, unreadcount = unread, SenderNick = _blogUtil.GetNickName(message.Sender), RecipientNick = _blogUtil.GetNickName(message.Recipient) })); } return(NotFound()); }