Exemple #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;
        }
        public ActionResult CreatePost(string slug, Thread thread, FormCollection collection)
        {
            // add post to post id

            User profile = Users.GetLoggedInUser();
            DidacheDb db = new DidacheDb();

            // make thread
            thread.UserID = profile.UserID;
            thread.TotalReplies = 0;
            thread.TotalViews = 0;
            thread.ThreadDate = DateTime.Now;
            thread.UserName = profile.Username;
            thread.LastPostUserName = profile.Username;
            thread.LastPostUserID = profile.UserID;
            thread.LastPostID = 0;
            thread.LastPostDate = DateTime.Now;
            thread.LastPostSubject = collection["Subject"];

            db.Threads.Add(thread);
            db.SaveChanges();

            // add post to thread
            ForumPost post = new ForumPost();
            post.ThreadID = thread.ThreadID;
            post.ForumID = Int32.Parse(collection["ForumID"]);
            post.PostDate = DateTime.Now;
            post.UserID = profile.UserID;
            post.UserName = profile.FullName;
            post.ReplyToPostID = 0;
            post.Subject = collection["Subject"];
            post.PostContent = collection["PostContent"];
            post.PostContentFormatted = Forums.FormatPost(post.PostContent);

            db.ForumPosts.Add(post);
            db.SaveChanges();

            return RedirectToAction("Thread", new { slug = slug, id = thread.ThreadID });
        }
        public ActionResult Reply(string slug, int id, FormCollection collection)
        {
            // add post to thread id

            User profile = Users.GetLoggedInUser();

            ForumPost post = new ForumPost();
            post.ThreadID = id;
            post.ForumID = Int32.Parse(collection["ForumID"]);
            post.PostDate = DateTime.Now;
            post.UserID = profile.UserID;
            post.UserName = profile.FullName;
            post.ReplyToPostID = Int32.Parse(collection["ReplyToPostID"]);
            post.Subject = collection["Subject"];
            post.PostContent = collection["PostContent"];
            post.PostContentFormatted = Forums.FormatPost(post.PostContent);

            db.ForumPosts.Add(post);
            db.SaveChanges();

            Thread thread = db.Threads.Include("Posts").FirstOrDefault(t => t.ThreadID == id);

            thread.LastPostDate = DateTime.Now;
            thread.LastPostID = post.PostID;
            thread.LastPostUserID = profile.UserID;
            thread.TotalReplies = thread.Posts.Count - 1;
            thread.LastPostSubject = post.Subject;

            db.SaveChanges();

            return RedirectToAction("Thread", new { slug = slug, id = id });
        }