public async Task AddViewTrackingAsync(JournalViewTracker viewTracker, string userName) { bool trackingExists = false; if (viewTracker.JournalEntryId != null) { trackingExists = _db.JournalViewTracker.Any(x => x.JournalEntryId == viewTracker.JournalEntryId && x.UserName == userName); viewTracker.ReplyId = null; } else { trackingExists = _db.JournalViewTracker.Any(x => x.ReplyId == viewTracker.ReplyId && x.UserName == userName); viewTracker.JournalEntryId = null; } if (!trackingExists) { var journalViewTracker = new JournalViewTracker() { JournalEntryId = viewTracker.JournalEntryId, ReplyId = viewTracker.ReplyId, UserName = userName, CreatedOn = DateTime.Now }; _db.JournalViewTracker.Add(journalViewTracker); await _db.SaveChangesAsync(); } }
public bool GetViewTracking(JournalViewTracker viewTracker, string userName) { if (viewTracker.JournalEntryId != null) { return(_db.JournalViewTracker.Any(x => x.JournalEntryId == viewTracker.JournalEntryId && x.UserName == userName)); } else if (viewTracker.ReplyId != null) { return(_db.JournalViewTracker.Any(x => x.ReplyId == viewTracker.ReplyId && x.UserName == userName)); } return(false); }