Exemple #1
0
        public ActionResult CreatePost([Bind(Include = "PostID,PostPostedBy,PostTitle,PostType,PostDescription,PostIntendedFor,PostTime")] DashboardPost dashboardPost)
        {
            if (Session["auth"] == null)
            {
                return(RedirectToAction("Logout", "Logout"));
            }
            else
            {
                int userid = Convert.ToInt32(TempData.Peek("auth"));



                if (ModelState.IsValid)
                {
                    DashboardPost tempdashboardPost = new DashboardPost(userid, dashboardPost.PostTitle,
                                                                        dashboardPost.PostType, dashboardPost.PostIntendedFor, dashboardPost.PostDescription, DateTime.Now);
                    db.DashboardPosts.Add(tempdashboardPost);
                    db.SaveChanges();
                    return(RedirectToAction("AdminDashboard"));
                }

                ViewBag.PostPostedBy = new SelectList(db.Residents, "ResidentID", "ResidentName", dashboardPost.PostPostedBy);
                return(View(dashboardPost));
            }
        }
Exemple #2
0
        public ActionResult CreatePost([Bind(Include = "PostID,PostPostedBy,PostTitle,PostType,PostDescription,PostIntendedFor,PostTime")] DashboardPost dashboardPost)
        {
            //Session["auth"] = 12;
            if (Session["auth"] == null)
            {
                return(RedirectToAction("Logout", "Logout"));
            }
            else
            {
                int      userid = Convert.ToInt32(Session["auth"]);
                Resident tempr  = db.Residents.FirstOrDefault(res => res.ResidentID == userid);
                TempData["UserName"] = tempr.ResidentName;



                if (ModelState.IsValid)
                {
                    DashboardPost tempdashboardPost = new DashboardPost(userid, dashboardPost.PostTitle,
                                                                        dashboardPost.PostType, dashboardPost.PostIntendedFor, dashboardPost.PostDescription, DateTime.Now);
                    db.DashboardPosts.Add(tempdashboardPost);
                    db.SaveChanges();
                    return(RedirectToAction("VieworDeletePosts"));
                }
                return(View(dashboardPost));
            }
        }
Exemple #3
0
        public ActionResult DeletePost(int id)
        {
            DashboardPost dp = db.DashboardPosts.Find(id);

            if (dp != null)
            {
                CourseUser cu = currentCourses.FirstOrDefault(c => c.AbstractCourseID == dp.CourseUser.AbstractCourseID);
                if ((dp.CourseUserID == ActiveCourseUser.ID) || ((cu != null) && (cu.AbstractRole.CanGrade)))
                {
                    dp.Replies.Clear();
                    db.SaveChanges();
                    db.DashboardPosts.Remove(dp);
                    db.SaveChanges();
                }
                else
                {
                    Response.StatusCode = 403;
                }
            }
            else
            {
                Response.StatusCode = 403;
            }

            return(View("_AjaxEmpty"));
        }
Exemple #4
0
        public ActionResult DeleteConfirmed(int id)
        {
            DashboardPost dashboardPost = db.DashboardPosts.Find(id);

            db.DashboardPosts.Remove(dashboardPost);
            db.SaveChanges();
            return(RedirectToAction("DeletePosts"));
        }
        public bool PostActivityMessage(string message, int courseId, string authToken)
        {
            //validate the user
            if (!IsValidKey(authToken))
            {
                return(false);
            }

            //because "currentUser" was pulled from a previous DB context, we need
            //to repull using the current context
            int         profileId   = activeSessions[authToken].UserProfile.ID;
            UserProfile currentUser = (from u in db.UserProfiles
                                       where u.ID == profileId
                                       select u).FirstOrDefault();

            if (currentUser == null)
            {
                return(false);
            }

            //find the course
            Course course = (from c in db.Courses
                             where c.ID == courseId
                             select c).FirstOrDefault();

            if (course == null)
            {
                return(false);
            }

            CourseUser courseUser = (from cu in db.CourseUsers
                                     where cu.UserProfileID == currentUser.ID
                                     &&
                                     cu.AbstractCourseID == course.ID
                                     select cu
                                     ).FirstOrDefault();

            if (courseUser == null)
            {
                return(false);
            }

            //use the data provided to create a new dashboard post
            DashboardPost newDp = new DashboardPost();

            newDp.Content    = message;
            newDp.Posted     = DateTime.UtcNow;
            newDp.CourseUser = courseUser;

            //add & save
            db.DashboardPosts.Add(newDp);
            db.SaveChanges();

            //return success
            return(true);
        }
Exemple #6
0
        /// <summary>
        /// Views a particular dashboard post thread by itself.
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult ViewThread(int id)
        {
            DashboardPost dp = db.DashboardPosts.Find(id);

            // Ensure post exists and that user is in the course.
            if (dp == null || (currentCourses.Any(cc => cc.AbstractCourseID == dp.CourseUser.AbstractCourseID)))
            {
                return(RedirectToAction("Index"));
            }

            SetupPostDisplay(dp);
            ViewBag.DashboardPost = dp;

            ViewBag.DashboardSingleCourseMode = false; // Force course/community prefixes to show when viewing thread.

            return(View(dp));
        }
Exemple #7
0
 public ActionResult DeleteConfirmed_Post(int id)
 {
     //Session["auth"] = 12;
     if (Session["auth"] == null)
     {
         return(RedirectToAction("Logout", "Logout"));
     }
     else
     {
         int      userid = Convert.ToInt32(Session["auth"]);
         Resident tempr  = db.Residents.FirstOrDefault(res => res.ResidentID == userid);
         TempData["UserName"] = tempr.ResidentName;
         DashboardPost dashboardPost = db.DashboardPosts.Find(id);
         db.DashboardPosts.Remove(dashboardPost);
         db.SaveChanges();
         return(RedirectToAction("VieworDeletePosts"));
     }
 }
        public void SendDashboardNotification(DashboardPost dp, CourseUser poster)
        {
            List <CourseUser> sendToUsers = new List <CourseUser>();

            // Send notification to original thread poster if poster is not anonymized,
            // are still in the course,
            // and are not the poster of the new reply.
            if (poster != null && !poster.AbstractRole.Anonymized && dp.CourseUserID != poster.ID)
            {
                sendToUsers.Add(dp.CourseUser);
            }

            foreach (DashboardReply reply in dp.Replies)
            {
                // Send notifications to each participant as long as they are not anonymized,
                // are still in the course,
                // and are not the poster of the new reply.
                // Also checks to make sure a duplicate notification is not sent.
                if (poster != null && (reply.CourseUser != null && !reply.CourseUser.AbstractRole.Anonymized && reply.CourseUserID != poster.ID && !sendToUsers.Contains(reply.CourseUser)))
                {
                    sendToUsers.Add(reply.CourseUser);
                }
            }

            // Send notification to each valid user.
            foreach (CourseUser courseUser in sendToUsers)
            {
                //ignore null course users
                if (courseUser == null)
                {
                    continue;
                }
                Notification n = new Notification();
                n.ItemType    = Notification.Types.Dashboard;
                n.ItemID      = dp.ID;
                n.RecipientID = courseUser.ID;
                if (poster != null)
                {
                    n.SenderID = poster.ID;
                }
                addNotification(n);
            }
        }
Exemple #9
0
 // GET: DashboardPosts/Delete/5
 public ActionResult Delete(int?id)
 {
     if (Session["auth"] == null)
     {
         return(RedirectToAction("Logout", "Logout"));
     }
     else
     {
         if (id == null)
         {
             return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
         }
         DashboardPost dashboardPost = db.DashboardPosts.Find(id);
         if (dashboardPost == null)
         {
             return(HttpNotFound());
         }
         return(View(dashboardPost));
     }
 }
Exemple #10
0
 // GET: DashboardPosts/Delete/5
 public ActionResult DeletePost(int?id)
 {
     //Session["auth"] = 12;
     if (Session["auth"] == null)
     {
         return(RedirectToAction("Logout", "Logout"));
     }
     else
     {
         int      userid = Convert.ToInt32(Session["auth"]);
         Resident tempr  = db.Residents.FirstOrDefault(res => res.ResidentID == userid);
         TempData["UserName"] = tempr.ResidentName;
         if (id == null)
         {
             return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
         }
         DashboardPost dashboardPost = db.DashboardPosts.Find(id);
         if (dashboardPost == null)
         {
             return(HttpNotFound());
         }
         return(View(dashboardPost));
     }
 }
Exemple #11
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"));
        }
Exemple #12
0
        public ActionResult NewPost(DashboardPost dp)
        {
            dp.CourseUser = ActiveCourseUser;
            dp.Posted     = DateTime.UtcNow;

            List <CourseUser> coursesToPost = new List <CourseUser>();

            bool sendEmail = Convert.ToBoolean(Request.Form["send_email"]);

            if (Request.Form["post_active"] != null)
            { // Post to active course only.
                coursesToPost.Add(ActiveCourseUser);
            }
            else if (Request.Form["post_all"] != null)
            { // Post to all courses.
                coursesToPost = currentCourses.Where(cu => cu.AbstractCourse is Course && cu.AbstractRole.CanModify && !cu.Hidden).ToList();
            }

            foreach (CourseUser cu in coursesToPost)
            {
                AbstractCourse c = cu.AbstractCourse;
                if (cu.AbstractRole.CanGrade || ((c != null) && (c.AllowDashboardPosts)))
                {
                    DashboardPost newDp = new DashboardPost
                    {
                        Content    = dp.Content,
                        Posted     = dp.Posted,
                        CourseUser = dp.CourseUser
                    };

                    if (ModelState.IsValid)
                    {
                        db.DashboardPosts.Add(newDp);
                        db.SaveChanges();

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


                        //slightly different messages depending on course type
                        if (c is Course)
                        {
                            Course course = c as Course;
                            subject = "[" + course.Prefix + " " + course.Number + "] New Activity Post from " + CurrentUser.FirstName + " " + CurrentUser.LastName;
                            body    = CurrentUser.FirstName + " " + CurrentUser.LastName + " sent the following message to the class at " + dp.Posted.UTCToCourse(ActiveCourseUser.AbstractCourseID).ToString() + ":";
                        }
                        else if (c is Community)
                        {
                            Community community = c as Community;
                            subject = "[" + community.Nickname + "] New Activity Post from " + CurrentUser.FirstName + " " + CurrentUser.LastName;
                            body    = CurrentUser.FirstName + " " + CurrentUser.LastName + " sent the following message to the community at " + dp.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 " + dp.Posted.UTCToCourse(ActiveCourseUser.AbstractCourseID).ToString() + ":";
                        }
                        body += "<br /><br />";
                        body += dp.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>",
                                              newDp.CourseUser.AbstractCourseID,
                                              newDp.ID
                                              );

                        List <CourseUser> courseUser = db.CourseUsers.Where(couseuser => couseuser.AbstractCourseID == c.ID).ToList();

                        //Who gets this email?  If the instructor desires, we send to everyone
                        if (c != null && sendEmail && cu.AbstractRole.CanModify)
                        {
                            foreach (CourseUser member in courseUser)
                            {
                                if (member.UserProfile.UserName != null) // Ignore pending users
                                {
                                    addresses.Add(new MailAddress(member.UserProfile.UserName, member.UserProfile.FirstName + " " + member.UserProfile.LastName));
                                }
                            }
                        }
                        //If the instructor didn't want to send to everyone, only send to those
                        //that want to receive everything
                        else
                        {
                            foreach (CourseUser member in courseUser)
                            {
                                if (member.UserProfile.UserName != null && member.UserProfile.EmailAllActivityPosts) // Ignore pending users
                                {
                                    addresses.Add(new MailAddress(member.UserProfile.UserName, member.UserProfile.FirstName + " " + member.UserProfile.LastName));
                                }
                            }
                        }

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

            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Exemple #13
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);
                }
            }
        }