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 TaskTypeResult ProcessFormCollection(int taskID, int userID, FormCollection collection, HttpRequestBase request)
        {
            DidacheDb db = new DidacheDb();

            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];

                studentFile = CourseFiles.SaveStudentFile(userID, data, file);
            }

            if (studentFile == null) {
                return new TaskTypeResult() { Success = false, Message = "No file" };
            } else {

                data.StudentSubmitDate = DateTime.Now;
                data.StudentFileID = studentFile.FileID;
                data.TaskCompletionStatus = TaskCompletionStatus.Completed;

                db.SaveChanges();

                return new TaskTypeResult() { Success = true };
            }
        }
Beispiel #4
0
        public TaskTypeResult ProcessFormCollection(int taskID, int userID, FormCollection collection, HttpRequestBase request)
        {
            DidacheDb db = new DidacheDb();

            UserTaskData data = db.UserTasks.SingleOrDefault(d=> d.TaskID == taskID && d.UserID == userID);

            // save completion status!
            data.TaskCompletionStatus = TaskCompletionStatus.Completed;
            db.SaveChanges();

            return new TaskTypeResult () { Success = true };
        }
        public ActionResult Edit(DiscussionGroup model, HttpPostedFileBase groupimage)
        {
            DidacheDb db = new DidacheDb();

            try {
                // store the old email so we can know if it's changed
                DiscussionGroup group = db.DiscussionGroups.Find(model.GroupID);

                UpdateModel(group);

                db.SaveChanges();

                // do image

                // double check for image type
                if (groupimage != null && groupimage.ContentLength > 0 && System.Text.RegularExpressions.Regex.IsMatch(groupimage.FileName, "(jpeg|jpg|jpe)$", System.Text.RegularExpressions.RegexOptions.IgnoreCase)) {

                    // save it to new path
                    string groupOriginalPath = Server.MapPath("~/images/groups/" + model.GroupID + "-original.jpg");
                    string groupProfilePath = Server.MapPath("~/images/groups/" + model.GroupID + ".jpg");
                    string groupThumbPath = Server.MapPath("~/images/groups/" + model.GroupID + "-thumb.jpg");

                    if (System.IO.File.Exists(groupOriginalPath))
                        System.IO.File.Delete(groupOriginalPath);

                    if (System.IO.File.Exists(groupProfilePath))
                        System.IO.File.Delete(groupProfilePath);

                    if (System.IO.File.Exists(groupThumbPath))
                        System.IO.File.Delete(groupThumbPath);

                    // save original for later
                    groupimage.SaveAs(groupOriginalPath);

                    // resize for profile
                    ImageTools.ScaleImage(groupOriginalPath, groupProfilePath, 180, 1000, 90);

                    // resize for thumb
                    ImageTools.ScaleImage(groupOriginalPath, groupThumbPath, 50, 50, 90);
                }

                return Redirect(group.GroupUrl);

            } catch (Exception ex) {
                ModelState.AddModelError("", "Edit Failure, see inner exception: " + ex.ToString());

                //throw ex;

                return View(model);
            }
        }
        public TaskTypeResult ProcessFormCollection(int taskID, int userID, FormCollection collection, HttpRequestBase request)
        {
            DidacheDb db = new DidacheDb();

            UserTaskData data = db.UserTasks.SingleOrDefault(d=> d.TaskID == taskID && d.UserID == userID);

            data.TaskCompletionStatus = (TaskCompletionStatus)Int32.Parse(collection["TaskStatus"]);
            data.StudentSubmitDate = DateTime.Now;
            data.NumericGrade = null;

            db.SaveChanges();

            return new TaskTypeResult () { Success = true };
        }
Beispiel #7
0
        public TaskTypeResult ProcessFormCollection(int taskID, int userID, FormCollection collection, HttpRequestBase request)
        {
            DidacheDb db = new DidacheDb();

            UserTaskData data = db.UserTasks.SingleOrDefault(d=> d.TaskID == taskID && d.UserID == userID);

            // store comments
            data.StudentSubmitDate = DateTime.Now;
            data.TaskCompletionStatus = TaskCompletionStatus.Completed;
            data.StudentComments = collection["usercomment"];

            db.SaveChanges();

            return new TaskTypeResult() { Success = true };
        }
        public TaskTypeResult ProcessFormCollection(int taskID, int userID, FormCollection collection, HttpRequestBase request)
        {
            DidacheDb db = new DidacheDb();

            UserTaskData data = db.UserTasks.SingleOrDefault(d => d.TaskID == taskID && d.UserID == userID);

            data.TaskCompletionStatus = (TaskCompletionStatus)Int32.Parse(collection["TaskStatus"]);
            data.StudentSubmitDate = DateTime.Now;

            int percentComplete = -1;
            if (Int32.TryParse(collection["PercentComplete"], out percentComplete) && percentComplete >= 1 && percentComplete <= 100) {

                data.NumericGrade = percentComplete;

                db.SaveChanges();

                return new TaskTypeResult() { Success = true };

            } else {
                return new TaskTypeResult() { Success = false };

            }
        }
        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});
            }
        }
Beispiel #10
0
        public ActionResult TaskFile2(int taskID, FormCollection collection)
        {
            User user = Users.GetLoggedInUser();

            UserTaskData data = Tasks.GetUserTaskData(taskID, user.UserID);

            Guid uniqueID = Guid.NewGuid();
            string originalFilename = "";
            string originalExtension = "";
            int fileID = 0;
            HttpPostedFileBase file = null;

            // save file
            if (Request.Files.Count > 0 && Request.Files[0].ContentLength > 0) {
                file = Request.Files[0];

                originalFilename = Path.GetFileName(file.FileName);
                originalExtension = Path.GetExtension(file.FileName);

                string filePath = Path.Combine(Settings.StudentFilesLocation, uniqueID.ToString() + originalExtension);
                file.SaveAs(filePath);

                StudentFile studentFile = new StudentFile();
                studentFile.UserID = user.UserID;
                studentFile.UniqueID = uniqueID;
                studentFile.ContentType = file.ContentType;
                studentFile.Length = file.ContentLength;
                studentFile.Filename = originalFilename;
                studentFile.UploadedDate = DateTime.Now;

                var db = new DidacheDb();
                db.StudentFiles.Add(studentFile);
                db.SaveChanges();

                fileID = studentFile.FileID;
            }

            // do processing
            object returnObject = new {
                success= true,
                fileID = fileID,
                fileLength=file.ContentLength,
                filename=originalFilename
            }; // Didache.TaskTypes.TaskTypeManager.ProcessFormCollection(data.Task.TaskTypeName, taskID, userID, collection, Request);

            return Json(returnObject);

            //return Redirect("/courses/" + data.Task.Course.Slug + "/schedule/" + data.Task.UnitID);
        }
        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 };
            }
        }
        public ActionResult EditProfile(User model)
        {
            DidacheDb db = new DidacheDb();

            try {
                // store the old email so we can know if it's changed
                User user = db.Users.Find(model.UserID);
                string oldEmail = user.Email;

                UpdateModel(user);

                // fix stuff
                if (!String.IsNullOrEmpty(user.Twitter) && user.Twitter.Contains("/")) {
                    user.Twitter = user.Twitter.Substring(user.Twitter.LastIndexOf("/") + 1);
                }
                if (!String.IsNullOrEmpty(user.Facebook) && user.Facebook.Contains("facebook.com")) {
                    user.Facebook = user.Facebook
                                            .Replace("http://", "")
                                            .Replace("https://", "")
                                            .Replace("www.facebook.com/", "")
                                            .Replace("facebook.com/", "");
                }
                if (!String.IsNullOrEmpty(user.Website) && !user.Website.Contains("http")) {
                    user.Website = "http://" + user.Website;
                }

                UserAction ua = new UserAction() {
                    SourceUserID = user.UserID,
                    TargetUserID = 0,
                    UserActionType = UserActionType.UpdateSettings,
                    ActionDate = DateTime.Now,
                    GroupID = 0,
                    MessageID = 0,
                    PostCommentID = 0,
                    PostID = 0,
                    Text = ""
                };
                db.UserActions.Add(ua);

                db.SaveChanges();

                // change of email changes
                if (user.Email != oldEmail) {

                    // change membership user
                    MembershipUser membershipUser = Membership.GetUser(user.Username, true);
                    membershipUser.Email = model.Email;
                    Membership.UpdateUser(membershipUser);

                    // send to CARS
                    // set to CampusNet
                    try {
                        string transactionUrl = "https://campus.dts.edu/cgi-bin/public/DSchkhold.cgi?id=" + user.UserID.ToString() + "&email=" + user.Email;
                        WebClient webClient = new WebClient();
                        string returnValue = webClient.DownloadString(transactionUrl);
                    }
                    catch {
                        // don't worry. be happy.
                    }
                }

                // save language to cookie for logout
                Response.Cookies.Add(new HttpCookie("Language", model.Language));

                Users.ClearUserCache(user);

                return Redirect(user.ProfileDisplayUrl); // RedirectToAction("EditProfile");

            } catch (Exception ex) {
                ModelState.AddModelError("", "Edit Failure, see inner exception: " + ex.ToString());

                return View(model);
            }
        }