Ejemplo n.º 1
0
        public ActionResult DeleteReply(int id)
        {
            DashboardReply dr = db.DashboardReplies.Find(id);

            if (dr != null)
            {
                CourseUser cu = currentCourses.FirstOrDefault(c => c.AbstractCourse == dr.Parent.CourseUser.AbstractCourse);
                if ((dr.CourseUserID == ActiveCourseUser.ID) || ((cu != null) && (cu.AbstractRole.CanGrade)))
                {
                    db.DashboardReplies.Remove(dr);
                    db.SaveChanges();
                }
                else
                {
                    Response.StatusCode = 403;
                }
            }
            else
            {
                Response.StatusCode = 403;
            }
            return(View("_AjaxEmpty"));
        }
Ejemplo n.º 2
0
        public ActionResult NewReply(DashboardReply dr)
        {
            if (ModelState.IsValid)
            {
                dr.CourseUser = ActiveCourseUser;
                dr.Posted     = DateTime.UtcNow;

                int replyTo = 0;
                if (Request.Form["reply_to"] != null)
                {
                    replyTo = Convert.ToInt32(Request.Form["reply_to"]);
                }

                int latestReply = 0;
                if (Request.Form["latest_reply"] != null)
                {
                    latestReply = Convert.ToInt32(Request.Form["latest_reply"]);
                }

                DashboardPost replyToPost = db.DashboardPosts.Find(replyTo);
                if (replyToPost != null)
                { // Does the post we're replying to exist?
                    // Are we a member of the course we're replying to?
                    CourseUser cu = (from c in currentCourses
                                     where c.AbstractCourseID == replyToPost.CourseUser.AbstractCourseID
                                     select c).FirstOrDefault();

                    AbstractCourse ac = null;
                    if (cu != null)
                    {
                        ac = cu.AbstractCourse;
                    }
                    if ((cu != null) && (cu.AbstractRole.CanGrade || ((ac != null) && (ac.AllowDashboardPosts))))
                    {
                        replyToPost.Replies.Add(dr);
                        db.SaveChanges();

                        //construct the subject & body
                        string             subject   = "";
                        string             body      = "";
                        List <MailAddress> addresses = new List <MailAddress>();

                        ViewBag.dp = replyToPost;
                        List <DashboardReply> replys = replyToPost.Replies.Where(r => r.ID > latestReply).ToList();

                        //slightly different messages depending on course type
                        if (ac is Course && (ac as Course).AllowDashboardReplies)
                        {
                            Course course = (Course)ac;
                            subject = "[" + course.Prefix + " " + course.Number + "] Reply from " + CurrentUser.FirstName + " " + CurrentUser.LastName;
                            body    = CurrentUser.FirstName + " " + CurrentUser.LastName + " sent the following reply to the Dashboard post " + replyToPost.DisplayTitle + " at " + dr.Posted.UTCToCourse(ActiveCourseUser.AbstractCourseID).ToString() + ":";
                        }
                        else if (ac is Community)
                        {
                            Community community = ac as Community;
                            subject = "[" + community.Nickname + "] Reply from " + CurrentUser.FirstName + " " + CurrentUser.LastName;
                            body    = CurrentUser.FirstName + " " + CurrentUser.LastName + " sent the following reply to the Dashboard post " + replyToPost.DisplayTitle + " at " + dr.Posted.UTCToCourse(ActiveCourseUser.AbstractCourseID).ToString() + ":";
                        }
                        else
                        {
                            //this should never execute, but just in case...
                            subject = "OSBLE Activity Post";
                            body    = CurrentUser.FirstName + " " + CurrentUser.LastName + " sent the following message at " + dr.Posted.UTCToCourse(ActiveCourseUser.AbstractCourseID).ToString() + ":";
                        }
                        body += "<br /><br />";
                        body += dr.Content.Replace("\n", "<br />");
                        body += string.Format("<br /><br /><a href=\"http://plus.osble.org/Home/Course?courseId={0}&postId={1}\">View and reply to post in OSBLE</a>",
                                              dr.CourseUser.AbstractCourseID,
                                              dr.ID
                                              );

                        //List<CoursesUsers> courseUsers = db.CoursesUsers.Where(c => (c.AbstractCourseID == ac.ID && c.UserProfile.EmailAllActivityPosts)).ToList();
                        List <CourseUser> courseUsers = (from c in db.CourseUsers
                                                         where c.AbstractCourseID == ac.ID &&
                                                         c.UserProfile.EmailAllActivityPosts &&
                                                         c.UserProfileID != CurrentUser.ID
                                                         select c).ToList();

                        foreach (CourseUser member in courseUsers)
                        {
                            if (member.UserProfile.UserName != null) // Ignore pending users
                            {
                                addresses.Add(new MailAddress(member.UserProfile.UserName, member.UserProfile.FirstName + " " + member.UserProfile.LastName));
                            }
                        }

                        //Send the message
                        Email.Send(subject, body, addresses);

                        foreach (DashboardReply r in replys)
                        {
                            SetupPostDisplay(r);
                        }

                        replys.Clear();
                        replys.Add(dr);
                        ViewBag.DashboardReplies = replys;

                        // Post notification to other thread participants
                        using (NotificationController nc = new NotificationController())
                        {
                            nc.SendDashboardNotification(dr.Parent, dr.CourseUser);
                        }
                    }
                    else
                    {
                        Response.StatusCode = 403;
                    }
                }
                else
                {
                    Response.StatusCode = 403;
                }
            }

            return(View("_SubDashboardReply"));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Sets up display settings for dashboard posts and replies.
        /// </summary>
        /// <param name="post">The post or reply to be set up</param>
        private void SetupPostDisplay(AbstractDashboard post)
        {
            List <CourseUser> courseList = new List <CourseUser>();

            // Get list of users in course, either from the root post or its parent in the case of a reply.
            if (post is DashboardPost)
            {
                DashboardPost dp = (DashboardPost)post;
                courseList = db.CourseUsers.Where(c => c.AbstractCourseID == dp.CourseUser.AbstractCourseID).ToList();
            }
            else if (post is DashboardReply)
            {
                DashboardReply dr = (DashboardReply)post;
                courseList = db.CourseUsers.Where(c => c.AbstractCourseID == dr.Parent.CourseUser.AbstractCourseID).ToList();
            }

            // Get Course/User link for current user.
            CourseUser currentCu = courseList.FirstOrDefault(c => c.UserProfileID == CurrentUser.ID);

            // " " for poster of post/reply.
            CourseUser posterCu = courseList.FirstOrDefault(c => c.UserProfileID == post.CourseUser.UserProfileID);


            /*** Setup Display Name/Display Title/Profile Picture/Mail Button/Delete Button ***/

            // If user is not anonymous, this post was written by current user, or the poster is an Instructor/TA, display name and picture.
            if (currentCu != null &&
                ((posterCu == null) || !currentCu.AbstractRole.Anonymized ||
                 (currentCu.UserProfileID == posterCu.UserProfileID) || posterCu.AbstractRole.CanGrade))
            {
                // Display Name (may be anonymous depending on currentCu's AbstractRoleID)
                post.DisplayName = posterCu != null
                    ? posterCu.DisplayName(currentCu.AbstractRoleID, true)
                    : "Deleted User";

                // Allow deletion if current user is poster or is an instructor
                if (currentCu.AbstractRole.CanModify ||
                    ((posterCu != null) && (posterCu.UserProfileID == currentCu.UserProfileID)))
                {
                    post.CanDelete = true;
                }

                // If current user is not the poster, allow mailing
                if (posterCu != null && posterCu.UserProfileID != currentCu.UserProfileID)
                {
                    Course course = db.AbstractCourses.Where(ac => ac.ID == ActiveCourseUser.AbstractCourseID).FirstOrDefault() as Course;
                    if (null != course && course.HideMail)
                    {
                        post.CanMail = false;
                    }
                    else
                    {
                        post.CanMail = true;
                    }
                }

                if (posterCu != null)
                {
                    // Display Titles for Instructors/TAs for Courses, or Leader of Communities.
                    post.DisplayTitle       = GetRoleTitle(posterCu.AbstractRoleID);
                    post.ShowProfilePicture = true;
                }
            }
            else
            {
                // Display Anonymous name (or "Deleted User")
                post.DisplayName = posterCu != null
                    ? posterCu.DisplayName((int)CourseRole.CourseRoles.Observer, true)
                    : "Deleted User";

                // Profile picture will display default picture.
                post.ShowProfilePicture = false;
                post.CanMail            = false;
                post.CanDelete          = false;
            }

            // For root posts only
            if (post is DashboardPost)
            {
                DashboardPost thisDp = (DashboardPost)post;

                // For posts, set reply box display if the course allows replies or if Instructor/TA/Observer.
                if (currentCu != null && ((currentCu.AbstractCourse is Course &&
                                           ((currentCu.AbstractCourse as Course).AllowDashboardReplies) ||
                                           (currentCu.AbstractRole.CanGrade) ||
                                           (currentCu.AbstractRole.Anonymized))
                                          // For communities, always allow replies
                                          || (currentCu.AbstractCourse is Community))
                    )
                {
                    thisDp.CanReply = true;
                }

                // recursively set the display for post's replies.
                foreach (DashboardReply dr in thisDp.Replies)
                {
                    SetupPostDisplay(dr);
                }
            }
        }