示例#1
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"));
            }
        }
示例#2
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"));
            }
        }