public TaskTypeResult ProcessFormCollection(int taskID, int userID, FormCollection collection, HttpRequestBase request) { DidacheDb db = new DidacheDb(); Task task = db.Tasks.Find(taskID); UserTaskData data = db.UserTasks.SingleOrDefault(d => d.TaskID == taskID && d.UserID == userID); // CREATE POST InteractionThread thread = new InteractionThread(); thread.UserID = userID; thread.TotalReplies = 0; thread.Subject = "Assignment: " + task.Name; thread.TaskID = taskID; thread.ThreadDate = DateTime.Now; db.InteractionThreads.Add(thread); db.SaveChanges(); InteractionPost post = new InteractionPost(); post.IsApproved = true; post.PostContent = request["usercomment"]; post.PostContentFormatted = Interactions.FormatPost(request["usercomment"]); post.PostDate = DateTime.Now; post.ReplyToPostID = 0; post.ThreadID = thread.ThreadID; post.UserID = userID; post.Subject = "RE: Assignment: " + task.Name; post.TaskID = taskID; db.InteractionPosts.Add(post); db.SaveChanges(); return new TaskTypeResult() { Success = true, UrlHash = "thread-" + thread.ThreadID }; }
public TaskTypeResult ProcessFormCollection(int taskID, int userID, FormCollection collection, HttpRequestBase request) { DidacheDb db = new DidacheDb(); Task task = db.Tasks.Find(taskID); UserTaskData data = db.UserTasks.SingleOrDefault(d=> d.TaskID == taskID && d.UserID == userID); // find the related task to send this post to int interactionTaskID = task.RelatedTaskID; // nasty lookup if (interactionTaskID == 0) { List<Task> possibleMatches = db.Tasks .Where(t => t.UnitID == task.UnitID && t.TaskTypeName == "CommentOnClassmatesFile") .OrderBy(t => t.SortOrder) .ToList(); if (possibleMatches.Count > 0) { interactionTaskID = possibleMatches[0].TaskID; } } // CREATE POST InteractionThread thread = new InteractionThread(); thread.UserID = userID; thread.TotalReplies = 0; thread.Subject = "Assignment: " + task.Name; thread.TaskID = interactionTaskID; thread.ThreadDate = DateTime.Now; db.InteractionThreads.Add(thread); db.SaveChanges(); InteractionPost post = new InteractionPost(); post.IsApproved = true; post.PostContent = request["usercomment"]; post.PostContentFormatted = Interactions.FormatPost(request["usercomment"]); post.PostDate = DateTime.Now; post.ReplyToPostID = 0; post.ThreadID = thread.ThreadID; post.UserID = userID; post.Subject = "RE: Assignment: " + task.Name; post.TaskID = interactionTaskID; db.InteractionPosts.Add(post); db.SaveChanges(); // facilty and facilitators if (data != null) { data.PostID = post.PostID; data.StudentSubmitDate = DateTime.Now; data.TaskCompletionStatus = TaskCompletionStatus.Completed; db.SaveChanges(); } return new TaskTypeResult() { Success = true, UrlHash = "thread-" + thread.ThreadID }; }
public ActionResult InteractionReply(FormCollection collection) { int threadID = 0; if (Int32.TryParse(collection["threadID"], out threadID)) { DidacheDb db = new DidacheDb(); User user = Users.GetLoggedInUser(); InteractionThread thread = db.InteractionThreads.Find(threadID); Task task = db.Tasks.Include("Course").SingleOrDefault(t => t.TaskID == thread.TaskID); InteractionPost post = new InteractionPost(); post.PostContent = collection["text"]; post.PostContentFormatted = Interactions.FormatPost(collection["text"]); post.IsApproved = true; post.IsDeleted = false; post.UserID = user.UserID; post.PostDate = DateTime.Now; post.ThreadID = threadID; post.TaskID = thread.TaskID; post.FileID = 0; post.Subject = "RE: " + thread.Subject; int replyToPostID = 0; if (!Int32.TryParse(collection["ReplyToPostID"], out replyToPostID)) { } post.ReplyToPostID = replyToPostID; db.InteractionPosts.Add(post); db.SaveChanges(); // check for completion List<InteractionThread> threads = db.InteractionThreads.Where(t => t.TaskID == thread.TaskID).ToList(); List<int> threadIDs = threads.Select(t => t.ThreadID).ToList(); List<InteractionPost> usersPostsForTask = db.InteractionPosts .Where(p => threadIDs.Contains(p.ThreadID) && p.UserID == user.UserID) .ToList(); int minimumInteractions = 4; // note: the student's initial task is also counted in this! bool isCompleted = false; if (usersPostsForTask.Count >= minimumInteractions) { isCompleted = true; UserTaskData data = db.UserTasks.SingleOrDefault(ud => ud.UserID == user.UserID && ud.TaskID == thread.TaskID); if (data != null) { data.TaskCompletionStatus = TaskCompletionStatus.Completed; db.SaveChanges(); } } // get all the posts, // where a user wants to get followups List<User> usersToNotify = db.InteractionPosts .Where(p => p.ThreadID == threadID && !p.IsDeleted && p.IsApproved && p.User.NotifyInteractionPostReplies) .Select(p => p.User) .Distinct() .ToList(); // check if thread starter wants replies if (thread.User.NotifyInteractionThreadsReplies) { usersToNotify.Add(thread.User); } // remove dups usersToNotify = usersToNotify.Distinct().ToList(); // remove commenter usersToNotify.RemoveAll(u => u.UserID == user.UserID); foreach (User userToNotify in usersToNotify) { string message = Emails.FormatEmail(Didache.Resources.emails.interaction_reply, task.Course, null, task, user, userToNotify, null, post, null); Emails.EnqueueEmail("*****@*****.**", userToNotify.Email, task.Course.CourseCode + ": Reply to " + task.Name, message, false); } /* // email responses List<User> usersToNotify = db.InteractionPosts .Where(p => p.ThreadID == threadID && !p.IsDeleted && p.IsApproved && p.UserID != user.UserID) .Select(p => p.User) .Distinct() .ToList(); // remove thread starter from replies if not wanted if (!thread.User.NotifyInteractionThreadsReplies) { usersToNotify.RemoveAll(u => u.UserID == thread.User.UserID); } foreach (User userToNotify in usersToNotify) { if (userToNotify.NotifyInteractionPostReplies || (userToNotify.UserID == thread.UserID && userToNotify.NotifyInteractionThreadsReplies)) { string message = Emails.FormatEmail(Didache.Resources.emails.interaction_reply, task.Course, null, task, user, userToNotify, null, post, null); Emails.EnqueueEmail("*****@*****.**", userToNotify.Email, task.Course.CourseCode + ": Reply to " + task.Name, message, false); } } * */ return Json(new { success = true, postID = post.PostID, user = serializer.Serialize(user), post = serializer.Serialize(post), isCompleted = isCompleted }); } else { return Json(new {success= false}); } }
public TaskTypeResult ProcessFormCollection(int taskID, int userID, FormCollection collection, HttpRequestBase request) { DidacheDb db = new DidacheDb(); Task task = db.Tasks.Find(taskID); UserTaskData data = db.UserTasks.SingleOrDefault(d=> d.TaskID == taskID && d.UserID == userID); StudentFile studentFile = null; // save file if (request.Files.Count > 0) { HttpPostedFileBase file = request.Files[0]; /* What if this is a GTA? * - Create a fake task for looking up and saving information */ UserTaskData dataForSaving = data; if (dataForSaving == null) { dataForSaving = new UserTaskData() { UserID = userID, TaskID = taskID }; } studentFile = CourseFiles.SaveStudentFile(userID, dataForSaving, file); } if (studentFile == null) { return new TaskTypeResult() { Success = false, Message = "No file" }; } else { // save this file, even if somethign messes up with the forums if (data != null) { data.StudentFileID = studentFile.FileID; db.SaveChanges(); } int interactionTaskID = task.RelatedTaskID; // nasty lookup if (interactionTaskID == 0) { List<Task> possibleMatches = db.Tasks .Where(t => t.UnitID == task.UnitID && t.TaskTypeName == "CommentOnClassmatesFile") .OrderBy(t => t.SortOrder) .ToList(); if (possibleMatches.Count > 0) { interactionTaskID = possibleMatches[0].TaskID; } } //if (interactionTaskID == 0) { // return new TaskTypeResult() { Success = false, Message = "No related task" }; //} InteractionThread thread = null; InteractionPost post = null; bool isNewPost = true; // check for existing thread/post if (data != null && data.PostID > 0) { post = db.InteractionPosts.SingleOrDefault(p => p.PostID == data.PostID); if (post != null) { thread = db.InteractionThreads.SingleOrDefault(t => t.ThreadID == post.ThreadID); if (thread != null) { isNewPost = false; } } } // CREATE POST if (isNewPost) { thread = new InteractionThread(); } thread.UserID = userID; thread.TotalReplies = 0; thread.IsDeleted = false; thread.Subject = "Assignment: " + task.Name; thread.TaskID = interactionTaskID; thread.ThreadDate = DateTime.Now; if (isNewPost) { db.InteractionThreads.Add(thread); } db.SaveChanges(); if (isNewPost) { post = new InteractionPost(); } post.IsApproved = true; post.IsDeleted = false; post.PostContent = request["usercomment"]; post.PostContentFormatted = Interactions.FormatPost(request["usercomment"]); post.PostDate = DateTime.Now; post.ReplyToPostID = 0; post.ThreadID = thread.ThreadID; post.UserID = userID; post.Subject = "RE: Assignment: " + task.Name; post.TaskID = interactionTaskID; post.FileID = studentFile.FileID; if (isNewPost) { db.InteractionPosts.Add(post); } db.SaveChanges(); if (data != null) { data.PostID = post.PostID; data.StudentSubmitDate = DateTime.Now; data.TaskCompletionStatus = TaskCompletionStatus.Completed; db.SaveChanges(); } return new TaskTypeResult() { Success = true, UrlHash = "thread-" + thread.ThreadID }; } }