public void MarkRead(int ideaId, int userId) { using (var context = new IdeaPoolEntities()) { UnReadDiscussion discussion = context.UnReadDiscussions.SingleOrDefault(x => x.IdeaId == ideaId && x.UserId == userId); if (discussion != null) { context.UnReadDiscussions.Remove(discussion); context.SaveChanges(); } } }
public void MarkUnread(int ideaId, List <int> userIds) { using (var context = new IdeaPoolEntities()) { foreach (int userid in userIds) { if (!context.UnReadDiscussions.Any(x => x.UserId == userid && x.IdeaId == ideaId)) { UnReadDiscussion unread = new UnReadDiscussion { IdeaId = ideaId, UserId = userid }; context.UnReadDiscussions.Add(unread); } } context.SaveChanges(); } }