/// <summary> /// Provides a details view for the provided Log IDs /// </summary> /// <param name="id">The ID(s) of the logs to retrieve. Accepts a comma delimited list. /// In the case of rendering multiple IDs, an aggregate view will be created /// </param> /// <returns></returns> public ActionResult Details(string id) { try { //make sure that we've gotten a valid ID if (string.IsNullOrEmpty(id)) { return(RedirectToAction("Index")); } //check to receive if we've gotten a single ID back int idAsInt = -1; if (Int32.TryParse(id, out idAsInt) == true) { //if we've received a log comment event or a helpful mark event, we have to reroute to the original event EventLog log = Db.EventLogs.Where(e => e.Id == idAsInt).FirstOrDefault(); //MarkReadProc.Update(idAsInt, CurrentUser.Id , true); if (log != null) { if (log.LogType == LogCommentEvent.Name) { LogCommentEvent commentEvent = Db.LogCommentEvents.Where(c => c.EventLogId == log.Id).FirstOrDefault(); return(RedirectToAction("Details", "Feed", new { id = commentEvent.SourceEventLogId })); } else if (log.LogType == HelpfulMarkGivenEvent.Name) { HelpfulMarkGivenEvent helpfulEvent = Db.HelpfulMarkGivenEvents.Where(e => e.EventLogId == log.Id).FirstOrDefault(); return(RedirectToAction("Details", "Feed", new { id = helpfulEvent.LogCommentEvent.SourceEventLogId })); } } } var query = new ActivityFeedQuery(); List <int> ids = ParseIdString(id); foreach (int logId in ids) { query.AddEventId(logId); } int testid = ids[0]; List <FeedItem> feedItems = query.Execute().ToList(); EventLog el = Db.EventLogs.Where(e => e.Id == testid).FirstOrDefault(); ExceptionEvent evt = Db.ExceptionEvents.Where(e => e.EventLogId == testid).FirstOrDefault(); FeedItem fi = new FeedItem() { Comments = new List <LogCommentEvent>(), //Creator = el.Sender, Event = evt, EventId = el.Id, HelpfulComments = 0, //Creator ItemDate = el.DateReceived, Log = el }; feedItems.Clear(); feedItems.Add(fi); List <AggregateFeedItem> aggregateItems = AggregateFeedItem.FromFeedItems(feedItems); //build the "you and 5 others got this error"-type messages FeedViewModel fvm = new FeedViewModel(); BuildEventRelations(fvm, feedItems); ViewBag.RecentUserErrors = fvm.RecentUserErrors; ViewBag.RecentClassErrors = fvm.RecentClassErrors; ViewBag.ErrorTypes = fvm.ErrorTypes; FeedDetailsViewModel vm = new FeedDetailsViewModel(); vm.Ids = id; vm.FeedItem = aggregateItems.FirstOrDefault(); if (Db.EventLogSubscriptions.Where(e => e.UserId == CurrentUser.Id).Where(e => e.LogId == ids.Min()).Count() > 0) { vm.IsSubscribed = true; } return(View(vm)); } catch (Exception ex) { LogErrorMessage(ex); return(RedirectToAction("FeedDown", "Error")); } }
public ActionResult Index(int?id, int timestamp = -1) { try { var query = new ActivityFeedQuery(); var subscriptionsQuery = new ActivityFeedQuery(); ProfileViewModel vm = new ProfileViewModel(); vm.User = CurrentUser; if (id != null) { OsbideUser user = Db.Users.Find(id); if (user != null) { vm.User = user; } } if (timestamp > 0) { DateTime pullDate = new DateTime(timestamp); query.StartDate = pullDate; } //Only show social events foreach (var evt in ActivityFeedQuery.GetSocialEvents()) { query.AddEventType(evt); subscriptionsQuery.AddEventType(evt); } //add in the list of users that the current person cares about query.AddSubscriptionSubject(vm.User); //build the feed view model vm.Feed = new FeedViewModel(); vm.Feed.Feed = AggregateFeedItem.FromFeedItems(query.Execute().ToList()); vm.Feed.LastLogId = -1; vm.Feed.SingleUserId = vm.User.Id; vm.Feed.LastPollDate = query.StartDate; vm.Score = Db.UserScores.Where(s => s.UserId == vm.User.Id).FirstOrDefault(); vm.NumberOfPosts = (from e in Db.EventLogs where (e.LogType == FeedPostEvent.Name || e.LogType == AskForHelpEvent.Name) && e.SenderId == vm.User.Id select e ).Count(); vm.NumberOfComments = Db.LogCommentEvents.Where(c => c.EventLog.SenderId == vm.User.Id).Count(); if (vm.Score == null) { vm.Score = new UserScore(); } var maxQuery = Db.EventLogs.Where(e => e.SenderId == vm.User.Id).Select(e => e.Id); if (maxQuery.Count() > 0) { vm.Feed.LastLogId = maxQuery.Max(); } // Build a catalog of recent commenting activity: // 1. Find all comments that the user has made // 2. Find all comments made by others on posts authored by the current user // 3. Find all comments made by others on posts on which the current user has written a comment DateTime maxLookback = DateTime.UtcNow.AddDays(-14); //1. find recent comments List <CommentActivityLog> socialLogs = (from social in Db.CommentActivityLogs .Include("TargetUser") .Include("LogCommentEvent") .Include("LogCommentEvent.SourceEventLog") .Include("LogCommentEvent.SourceEventLog.Sender") .Include("LogCommentEvent") .Include("LogCommentEvent.EventLog") .Include("LogCommentEvent.EventLog.Sender") where 1 == 1 && social.LogCommentEvent.EventDate >= maxLookback && (social.TargetUserId == vm.User.Id || social.LogCommentEvent.SourceEventLog.SenderId == vm.User.Id) orderby social.LogCommentEvent.EventDate descending select social ).ToList(); foreach (CommentActivityLog commentLog in socialLogs) { vm.SocialActivity.AddLog(commentLog); } //show subscriptions only if the user is accessing his own page if (vm.User.Id == CurrentUser.Id) { List <int> eventLogIds = Db.EventLogSubscriptions.Where(s => s.UserId == vm.User.Id).Select(s => s.LogId).ToList(); if (eventLogIds.Count > 0) { foreach (int logId in eventLogIds) { subscriptionsQuery.AddEventId(logId); } vm.EventLogSubscriptions = AggregateFeedItem.FromFeedItems(subscriptionsQuery.Execute().ToList()); } } return(View(vm)); } catch (Exception ex) { LogErrorMessage(ex); return(RedirectToAction("Index", "Error")); } }