Esempio n. 1
0
        public static string FormatEmail(string text, Course course, Unit unit, Task task, User fromUser, User toUser, UserTaskData userTaskData = null, InteractionPost interactionPost = null, ForumPost forumPost = null, UserPost userPost = null, UserPostComment userPostComment = null, DiscussionGroup discussionGroup = null)
        {
            if (course != null) {
                text = text.Replace("{course-code}", course.CourseCode + course.Section);
                text = text.Replace("{course-name}", course.Name);
            }

            if (fromUser != null) {
                text = text.Replace("{fromuser-secureformattedname}", fromUser.SecureFormattedName);
                text = text.Replace("{fromuser-secureshortname}", fromUser.SecureShortName);
            }

            if (toUser != null) {
                text = text.Replace("{touser-secureformattedname}", toUser.SecureFormattedName);
                text = text.Replace("{touser-secureshortname}", toUser.SecureShortName);
            }

            if (task != null) {
                text = text.Replace("{task-name}", task.Name);
            }

            if (userTaskData != null) {
                text = text.Replace("{usertaskdata-numericgrade}", userTaskData.NumericGrade.HasValue ? userTaskData.NumericGrade.Value.ToString() : "(none)");
                text = text.Replace("{usertaskdata-studentcomments}", userTaskData.StudentComments);
                text = text.Replace("{usertaskdata-gradercomments}", userTaskData.GraderComments);
                text = text.Replace("{usertaskdata-gradedfile-url}", userTaskData.GradedFile != null ? "https://online.dts.edu" + userTaskData.GradedFile.FileUrl : "");
                text = text.Replace("{usertaskdata-studentfile-url}", userTaskData.StudentFile != null ? "https://online.dts.edu" + userTaskData.StudentFile.FileUrl : "");
            }

            if (interactionPost != null) {
                text = text.Replace("{interactionpost-postcontent}", interactionPost.PostContent);
                text = text.Replace("{interactionpost-posturl}", "https://online.dts.edu" + interactionPost.PostUrl);
            }

            // NOTE: using unformated text for now?!
            if (userPost != null) {
                text = text.Replace("{userpost-text}", userPost.Text);
                text = text.Replace("{userpost-posturl}", "https://online.dts.edu" + userPost.PostUrl);
            }

            if (discussionGroup != null) {
                text = text.Replace("{discussiongroup-name}", discussionGroup.Name);
                text = text.Replace("{discussiongroup-groupurl}", "https://online.dts.edu" + discussionGroup.GroupUrl);
            }

            if (userPostComment != null) {
                text = text.Replace("{postcomment-text}", userPostComment.Text);
            }

            return text;
        }
Esempio n. 2
0
        public ActionResult CreateUserPostComment(string text, int postID)
        {
            User user = Users.GetLoggedInUser();
            UserPostComment newUserPostComment = null;
            try {
                newUserPostComment = new UserPostComment() {
                    UserID = user.UserID,
                    PostID = postID,
                    CommentDate = DateTime.Now,
                    IsDeleted = false,
                    Text = text,
                    TextFormatted = Markdown.Transform(text)
                    //TextFormatted = text.Replace("\n", "").Replace("\r", "<br />")
                };

                db.UserPostComments.Add(newUserPostComment);
                db.SaveChanges();
            } catch (Exception e) {

                return Json(new { success = false, message = e.ToString() });
            }

            // get the data back out
            newUserPostComment = db.UserPostComments
                        .Include("User")
                        .Single(uc => uc.PostCommentID == newUserPostComment.PostCommentID);

            // Send emails
            var post = db.UserPosts
                        .Include("User")
                        .Include("PostComments.User")
                        .SingleOrDefault(p => p.PostID == newUserPostComment.PostID);

            if (post != null) {
                // find peeps who want to be notified
                List<User> usersToBeNotified = post.PostComments
                                                        .Select(pc => pc.User)
                                                        .Where(u => u.NotifyUserPostCommentReplies)
                                                        .ToList();

                // check if starter wants a notification
                if (post.User.NotifyUserPostReplies) {
                    usersToBeNotified.Add(post.User);
                }

                // remove dups
                usersToBeNotified = usersToBeNotified.Distinct().ToList();

                // remove commenter
                usersToBeNotified.RemoveAll(u => u.UserID == user.UserID);

                foreach (User userToBeNotified in usersToBeNotified) {
                    Emails.EnqueueEmail(
                        "*****@*****.**",
                        userToBeNotified.Email,
                        "New Comment",
                        Emails.FormatEmail(Didache.Resources.emails.userpost_comment, null, null, null, user, userToBeNotified, null, null, null, post, newUserPostComment),
                        false);
                }
            }

            // user action
            db.UserActions.Add(new UserAction() {
                SourceUserID = user.UserID,
                ActionDate = DateTime.Now,
                UserActionType = UserActionType.MakeNewComment,
                PostID = newUserPostComment.PostID,
                Text = newUserPostComment.TextFormatted,
                GroupID = 0,
                MessageID = 0,
                PostCommentID = newUserPostComment.PostCommentID,
                TargetUserID = post.UserID
            });
            db.SaveChanges();

            return Json(new {
                    PostCommentID = newUserPostComment.PostCommentID,
                    CommentDate = newUserPostComment.CommentDate,
                    CommentDateFormatted = newUserPostComment.CommentDate.ToString("MMM d, hh:mm tt"),
                    //Text = Regex.Replace(c.TextFormatted, "</?(div|font|span|style|script|img).*?>", ""),
                    Text = newUserPostComment.TextFormatted,
                    User = new {
                        SecureFormattedName = newUserPostComment.User.SecureFormattedName,
                        ProfileDisplayUrl = newUserPostComment.User.ProfileDisplayUrl,
                        ProfileImageUrl = newUserPostComment.User.ProfileImageUrl
                    }

            });
        }