Exemplo 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;
        }
Exemplo n.º 2
0
        public static StudentFile SaveStudentFile(int userID, UserTaskData userData, HttpPostedFileBase file)
        {
            DidacheDb db = new DidacheDb();

            StudentFile studentFile = null;

            if (file.ContentLength > 0) {

                // setup data
                studentFile = new StudentFile();
                studentFile.UserID = userID;
                studentFile.UploadedDate = DateTime.Now;
                studentFile.UniqueID = Guid.NewGuid();
                studentFile.ContentType = file.ContentType;
                studentFile.Length = file.ContentLength;

                // setup physical file
                string extension = Path.GetExtension(file.FileName);
                string filenameWithoutExtension = Path.GetFileNameWithoutExtension(file.FileName);
                studentFile.Filename = Path.GetFileName(file.FileName);
                string savePath = Path.Combine(Settings.StudentFilesLocation, studentFile.UniqueID.ToString() + extension);

                // check file type
                /*
                if (!String.IsNullOrWhiteSpace(userData.Task.FileTypesAllowed)) {

                }
                */

                file.SaveAs(savePath);

                // save file info to DB
                db.StudentFiles.Add(studentFile);
                db.SaveChanges();
            }

            return studentFile;
        }
Exemplo n.º 3
0
        public static List<UserTaskData> GetUserTaskDataInUnit(int unitID, int userID, bool createFakeData)
        {
            DidacheDb db = new DidacheDb();
            List<UserTaskData> userTasks = null;

            if (createFakeData) {
                // for graders
                List<Task> tasks = db.Tasks.Where(t => t.UnitID == unitID).OrderBy(t => t.SortOrder).ToList();

                userTasks = new List<UserTaskData>();

                foreach (Task task in tasks) {
                    UserTaskData utd = new UserTaskData() {
                        TaskID = task.TaskID,
                        CourseID = task.CourseID,
                        UnitID = task.UnitID,
                        TaskCompletionStatus = TaskCompletionStatus.NotStarted,
                        Task = task
                    };

                    //utd.Task = task;

                    userTasks.Add(utd);
                }

            }
            else {
                userTasks = db.UserTasks
                    .Include("Task")
                    .Where(d => d.UserID == userID && d.Task.UnitID == unitID)
                    .OrderBy(d => d.Task.SortOrder)
                    .ToList();

            }

            return userTasks;
        }
Exemplo n.º 4
0
        public ActionResult UpdateTask(Task model)
        {
            if (model.TaskID > 0) {
                // EDIT MODE
                try {
                    model = db.Tasks.Find(model.TaskID);

                    UpdateModel(model);

                    db.SaveChanges();

                    // reciprocate
                    if (model.RelatedTaskID > 0) {
                        Task relatedTask = db.Tasks.Find(model.RelatedTaskID);
                        if (relatedTask != null) {
                            relatedTask.RelatedTaskID = model.TaskID;
                            db.SaveChanges();
                        }
                    }

                    return Json(new { success = true, task = serializer.Serialize(model) });
                } catch (Exception ex) {

                    Response.StatusCode = 500;
                    return Json(new { success = false, task = serializer.Serialize(model), message = "Update error", errors = GetErrors() });
                }
            } else {

                // ADD MODE
                if (ModelState.IsValid) {
                    db.Tasks.Add(model);
                    db.SaveChanges();

                    // reciprocate
                    if (model.RelatedTaskID > 0) {
                        Task relatedTask = db.Tasks.Find(model.RelatedTaskID);
                        if (relatedTask != null) {
                            relatedTask.RelatedTaskID = model.TaskID;
                            db.SaveChanges();
                        }
                    }

                    // create user tasks
                    List<CourseUser> users = db.CourseUsers.Where(cu => cu.CourseID == model.CourseID && cu.RoleID == (int) CourseUserRole.Student).ToList();
                    foreach (CourseUser user in users) {

                        UserTaskData utd = new UserTaskData() {
                            TaskID = model.TaskID,
                            CourseID = model.CourseID,
                            UnitID = model.UnitID,
                            GraderComments = "",
                            GraderSubmitDate = null,
                            GraderUserID = 0,
                            GradeStatus = 0,
                            LetterGrade = "",
                            NumericGrade = null,
                            StudentComments = "",
                            StudentSubmitDate = null,
                            TaskCompletionStatus = TaskCompletionStatus.NotStarted,
                            TaskData = "",
                            GraderFileID = 0,
                            PostID = 0,
                            StudentFileID = 0,
                            UserID = user.UserID
                        };

                        db.UserTasks.Add(utd);

                    }

                    db.SaveChanges();

                    return Json(new { success = true, task = serializer.Serialize(model) });
                } else {
                    Response.StatusCode = 500;
                    return Json(new { success = false, task = serializer.Serialize(model), message = "Add error", errors = GetErrors() });
                }
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="courseID"></param>
        /// <param name="userID"></param>
        /// <param name="groupID"></param>
        /// <param name="userRole"></param>
        /// <returns>Whether or not the user was added (false = just updated)</returns>
        public static bool AddUserToCourse(int courseID, int userID, int groupID, CourseUserRole userRole)
        {
            DidacheDb db = new DidacheDb();

            CourseUser courseUser = db.CourseUsers.SingleOrDefault(cu => cu.UserID == userID && cu.CourseID == courseID && cu.RoleID == (int) userRole);

            if (courseUser != null) {

                // update the group
                if (groupID > 0) {
                    courseUser.GroupID = groupID;
                    db.SaveChanges();
                }

                return false;
            } else {
                courseUser = new CourseUser() {
                    UserID = userID,
                    CourseID = courseID,
                    RoleID = (int) userRole,
                    GroupID = groupID
                };

                db.CourseUsers.Add(courseUser);

                if (userRole == CourseUserRole.Student) {

                    // check for assignments
                    bool hasTasks = db.UserTasks.Count(ut => ut.UserID == userID && ut.Task.CourseID == courseID) > 0;

                    if (!hasTasks) {

                        // create assignments
                        List<Task> tasks = db.Tasks.Where(t => t.CourseID == courseID).ToList();

                        foreach (Task task in tasks) {
                            UserTaskData utd = new UserTaskData() {
                                TaskID = task.TaskID,
                                CourseID = task.CourseID,
                                UnitID = task.UnitID,
                                GraderComments = "",
                                GraderSubmitDate = null,
                                GraderUserID = 0,
                                GradeStatus = 0,
                                LetterGrade = "",
                                NumericGrade = null,
                                StudentComments = "",
                                StudentSubmitDate = null,
                                TaskCompletionStatus = TaskCompletionStatus.NotStarted,
                                TaskData = "",
                                GraderFileID = 0,
                                PostID = 0,
                                StudentFileID = 0,
                                UserID = userID
                            };

                            db.UserTasks.Add(utd);
                        }
                    }
                }

                db.SaveChanges();
                return true;

            }
        }