예제 #1
0
        /// <summary>
        /// Returns a raw feed of past feed items without any extra HTML chrome.  Used for AJAX updates to an existing feed.
        /// </summary>
        /// <param name="id">The ID of the first feed item received by the client.</param>
        /// <returns></returns>
        public ActionResult OldFeedItems(int id, int count, int userId, int errorType = -1, string keyword = "", int hash = 0)
        {
            try
            {
                var query = new ActivityFeedQuery();
                query.CommentFilter = hash == 0 ? keyword : "#" + keyword;
                if (errorType > 0)
                {
                    query = new BuildErrorQuery(Db);
                    (query as BuildErrorQuery).BuildErrorTypeId = errorType;
                }
                BuildBasicQuery(query);
                query.MaxLogId     = id;
                query.MaxQuerySize = count;

                //used to build a feed for a single person.  Useful for building profile-based feeds
                if (userId > 0)
                {
                    query.ClearSubscriptionSubjects();
                    query.AddSubscriptionSubject(Db.Users.Where(u => u.Id == userId).FirstOrDefault());
                }

                List <FeedItem>          feedItems     = query.Execute().ToList();
                List <AggregateFeedItem> aggregateFeed = AggregateFeedItem.FromFeedItems(feedItems);


                //build the "you and 5 others got this error"-type messages
                FeedViewModel vm = new FeedViewModel();
                BuildEventRelations(vm, feedItems);

                ViewBag.RecentUserErrors  = vm.RecentUserErrors;
                ViewBag.RecentClassErrors = vm.RecentClassErrors;
                ViewBag.ErrorTypes        = vm.ErrorTypes;

                return(View("AjaxFeed", aggregateFeed));
            }
            catch (Exception ex)
            {
                LogErrorMessage(ex);
                return(RedirectToAction("FeedDown", "Error"));
            }
        }
예제 #2
0
        public ActionResult Index(int?id, int timestamp = -1)
        {
            if (null != ActiveCourseUser)
            {
                ViewBag.HideMail = OSBLE.Utility.DBHelper.GetAbstractCourseHideMailValue(ActiveCourseUser.AbstractCourseID);
            }
            else
            {
                ViewBag.HideMail     = true;
                ViewBag.errorMessage = "No user information yet available. Please sign up for a course first.";
                ViewBag.errorName    = "No Courses";
                return(View("Error"));
            }

            try
            {
                var query = new ActivityFeedQuery(ActiveCourseUser.AbstractCourseID);
                var subscriptionsQuery = new ActivityFeedQuery(ActiveCourseUser.AbstractCourseID);
                ProfileViewModel vm    = new ProfileViewModel();
                vm.User = CurrentUser;
                if (id != null)
                {
                    UserProfile user = DBHelper.GetUserProfile((int)id);
                    if (user != null && ActiveCourseUser.AbstractCourseID != (int)CourseRole.CourseRoles.Observer)
                    {
                        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();

                using (SqlConnection conn = DBHelper.GetNewConnection())
                {
                    int AskForHelpValue = conn.Query <int>("SELECT e.EventTypeId " +
                                                           "FROM EventTypes e " +
                                                           "WHERE e.EventTypeName = 'AskForHelpEvent' ").FirstOrDefault();
                    int FeedPostValue = conn.Query <int>("SELECT e.EventTypeId " +
                                                         "FROM EventTypes e " +
                                                         "WHERE e.EventTypeName = 'FeedPostEvent'").FirstOrDefault();
                    int LogCommentValue = conn.Query <int>("SELECT e.EventTypeId " +
                                                           "FROM EventTypes e " +
                                                           "WHERE e.EventTypeName = 'LogCommentEvent'").FirstOrDefault();

                    var posts = conn.Query <EventLog>(
                        "SELECT * " +
                        "FROM EventLogs " +
                        "WHERE EventTypeId = @fpe " +
                        "AND SenderId = @UserId " +
                        "ORDER BY EventDate DESC",
                        new { fpe = FeedPostValue, afhe = AskForHelpValue, UserId = vm.User.ID }).ToList();
                    vm.NumberOfPosts = posts.Count;

                    var comments = DBHelper.GetCommentsForUserID(vm.User.ID, conn);
                    //var comments = conn.Query<EventLog>(
                    //    "SELECT * " +
                    //    "FROM EventLogs e " +
                    //    "WHERE (e.EventTypeId = @lcv " +
                    //    "AND e.SenderId = @UserId) " +
                    //    "ORDERBY e.EventDate DESCENDING", new { lcv = LogCommentValue, UserId = CurrentUser.ID }).ToList();
                    vm.NumberOfComments = comments.Count();

                    //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();
                    //}

                    ////// need to figure this out
                    //////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
                    //c.LogCommentEvent
                    //c.Id
                    //c.LogCommentEventId
                    //c.UserProfile
                    //c.UserProfileId

                    int i = 0;
                    foreach (LogCommentEvent lce in comments)
                    {
                        lce.SourceEvent = DBHelper.GetActivityEvent(lce.SourceEventLogId, conn);
                        lce.Sender      = vm.User;

                        CommentActivityLog cal = new CommentActivityLog()
                        {
                            Id = i,
                            LogCommentEvent   = lce,
                            LogCommentEventId = lce.EventLogId,
                            UserProfile       = vm.User,
                            UserProfileId     = vm.User.ID
                        };
                        if (ActiveCourseUser.AbstractCourseID == (int)CourseRole.CourseRoles.Observer)
                        {
                            cal.UserProfileId = 0;
                        }

                        i++;
                        vm.SocialActivity.AddLog(cal);
                    }

                    //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();
                }
                //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());
                //    }

                //}

                ViewBag.IsInstructor   = ActiveCourseUser.AbstractRoleID == (int)CourseRole.CourseRoles.Instructor;
                ViewBag.IsSelf         = ActiveCourseUser != null ? ActiveCourseUser.UserProfileID == id || id == null : false;
                ViewBag.UploadedImages = GetImageFilesForCurrentUser();

                return(View(vm));
            }
            catch (Exception ex)
            {
                //LogErrorMessage(ex);
                ViewBag.errorMessage = ex.Message;
                ViewBag.errorName    = ex.GetType().ToString();
                return(View("Error"));
            }
        }
예제 #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="id">The ID of the last event received by the user.  Used for AJAX updates</param>
        /// <returns></returns>
        public ActionResult Index(long timestamp = -1, int errorType = -1, string errorTypeStr = "", string keyword = "", int hash = 0)
        {
            //turned off for now.
            //return RedirectToAction("FeedDown", "Error");
            try
            {
                var query = new ActivityFeedQuery();

                query.CommentFilter = hash == 0 ? keyword : "#" + keyword;

                //Two ways that we can receive an error type: by name (errorTypeStr) or by ID (errorType).
                //First, we check the string and see if we can match it to an ID number.  Then, we check
                //to see if we have a valid ID number.  If it doesn't work out, just work as normal.
                if (string.IsNullOrEmpty(errorTypeStr) == false)
                {
                    errorTypeStr = errorTypeStr.ToLower().Trim();
                    ErrorType type = Db.ErrorTypes.Where(e => e.Name.CompareTo(errorTypeStr) == 0).FirstOrDefault();
                    if (type != null)
                    {
                        errorType = type.Id;
                    }
                }
                if (errorType > 0)
                {
                    query = new BuildErrorQuery(Db);
                    (query as BuildErrorQuery).BuildErrorTypeId = errorType;
                }
                BuildBasicQuery(query);
                FeedViewModel vm = new FeedViewModel();

                if (timestamp > 0)
                {
                    DateTime pullDate = new DateTime(timestamp);
                    query.StartDate = pullDate;
                }
                else
                {
                    query.MaxQuerySize = 40;
                }

                //and finally, retrieve our list of feed items
                var maxIdQuery = Db.EventLogs.Select(l => l.Id);
                if (maxIdQuery.Count() > 0)
                {
                    vm.LastLogId = maxIdQuery.Max();
                }
                else
                {
                    vm.LastLogId = 0;
                }

                List <FeedItem>          feedItems     = query.Execute().ToList();
                List <AggregateFeedItem> aggregateFeed = AggregateFeedItem.FromFeedItems(feedItems);
                this.UpdateLogSubscriptions(CurrentUser);
                try
                {
                    vm.LastPollDate = aggregateFeed.Select(a => a.MostRecentOccurance).Max();
                }
                catch (Exception)
                {
                    vm.LastPollDate = DateTime.MinValue.AddDays(2);
                }
                vm.Feed = aggregateFeed;
                vm.EventFilterOptions     = ActivityFeedQuery.GetAllEvents().OrderBy(e => e.ToString()).ToList();
                vm.UserEventFilterOptions = query.ActiveEvents;
                vm.ErrorTypes             = Db.ErrorTypes.Distinct().ToList();
                vm.SelectedErrorType      = new ErrorType();
                if (errorType > 0)
                {
                    vm.SelectedErrorType = Db.ErrorTypes.Where(e => e.Id == errorType).FirstOrDefault();
                    if (vm.SelectedErrorType == null)
                    {
                        vm.SelectedErrorType = new ErrorType();
                    }
                }

                //build possible courses and user types
                vm.Courses = Db.Courses.ToList();
                vm.CourseRoles.Add(CourseRole.Student);
                vm.CourseRoles.Add(CourseRole.Assistant);
                vm.CourseRoles.Add(CourseRole.Coordinator);
                if (_userSettings != null)
                {
                    vm.SelectedCourseId   = _userSettings.CourseFilter;
                    vm.SelectedCourseRole = _userSettings.CourseRole;
                }

                //build the "you and 5 others got this error"-type messages
                BuildEventRelations(vm, feedItems);
                vm.Keyword = keyword;

                return(View(vm));
            }
            catch (Exception ex)
            {
                LogErrorMessage(ex);

                return(RedirectToAction("FeedDown", "Error"));
            }
        }
예제 #4
0
        /// <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"));
            }
        }
예제 #5
0
        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"));
            }
        }