public static string GetFriendlyFilename(Course course, Unit unit, Task task, User user, string filename) { return Regex.Replace(course.CourseCode + course.Section + "-Unit" + unit.SortOrder + "-" + task.Name.Replace(" ", "-") + "-" + user.FullName.Replace(" ", "-"), @"[\*\!\$\%\?;:]", "") + "[" + task.TaskID + "," + user.UserID + "]" + Path.GetExtension(filename); }
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 UpdateUnit(Unit model) { if (model.UnitID > 0) { // EDIT MODE try { model = db.Units.Find(model.UnitID); UpdateModel(model); db.SaveChanges(); return Json(new { success = true, unit = serializer.Serialize(model) }); } catch (Exception ex) { Response.StatusCode = 500; return Json(new { success = false, unit = serializer.Serialize(model), message = "Update error", errors = GetErrors() }); } } else { // ADD MODE if (ModelState.IsValid) { db.Units.Add(model); db.SaveChanges(); return Json(new { success = true, unit = serializer.Serialize(model) }); } else { Response.StatusCode = 500; return Json(new { success = false, unit = serializer.Serialize(model), message = "Add error", errors = GetErrors() }); } } }
public static Course CloneCourse(int courseID, int sessionID, DateTime startDate, string courseCode, string section) { DidacheDb db = new DidacheDb(); Course oldCourse = db.Courses .Include("Units.Tasks") .Include("CourseFileGroups.CourseFileAssociations") .SingleOrDefault(c => c.CourseID == courseID); int daysToShift = (startDate - oldCourse.StartDate).Days; Course newCourse = new Course() { SessionID = sessionID, CampusID = oldCourse.CampusID, IsActive = oldCourse.IsActive, CourseCode = !String.IsNullOrWhiteSpace(courseCode) ? courseCode : oldCourse.CourseCode, Name = oldCourse.Name, Section = !String.IsNullOrWhiteSpace(section) ? section : oldCourse.Section, StartDate = oldCourse.StartDate.AddDays(daysToShift), EndDate = oldCourse.EndDate.AddDays(daysToShift), Description = oldCourse.Description }; db.Courses.Add(newCourse); db.SaveChanges(); /* } catch (DbEntityValidationException dbEx) { string errors = ""; foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { //System.Web.HttpContext.Current.Trace.Warn("Property: {0} Error: {1}", validationError.PropertyName, dbEx); errors += string.Format("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage) + "; "; } } throw new Exception(errors); } */ foreach (Unit oldUnit in oldCourse.Units) { Unit newUnit = new Unit() { CourseID = newCourse.CourseID, IsActive = oldUnit.IsActive, SortOrder = oldUnit.SortOrder, Name = oldUnit.Name, StartDate = oldUnit.StartDate.AddDays(daysToShift), EndDate = oldUnit.EndDate.AddDays(daysToShift), Instructions = oldUnit.Instructions }; db.Units.Add(newUnit); db.SaveChanges(); Dictionary<int, int> taskMap = new Dictionary<int, int>(); List<Task> newTasks = new List<Task>(); foreach (Task oldTask in oldUnit.Tasks) { Task newTask = new Task() { CourseID = newUnit.CourseID, UnitID = newUnit.UnitID, IsActive = oldTask.IsActive, SortOrder = oldTask.SortOrder, Name = oldTask.Name, DueDate = null, FileTypesAllowed = oldTask.FileTypesAllowed, InstructionsAvailableDate = null, IsSkippable = oldTask.IsSkippable, Priority = oldTask.Priority, RelatedTaskID = oldTask.RelatedTaskID, SubmissionAvailableDate = null, TaskID = oldTask.TaskID, TaskTypeName = oldTask.TaskTypeName, Instructions = oldTask.Instructions, CustomAttributes = oldTask.CustomAttributes }; if (oldTask.DueDate.HasValue) newTask.DueDate = oldTask.DueDate.Value.AddDays(daysToShift); if (oldTask.SubmissionAvailableDate.HasValue) newTask.SubmissionAvailableDate = oldTask.SubmissionAvailableDate.Value.AddDays(daysToShift); if (oldTask.InstructionsAvailableDate.HasValue) newTask.InstructionsAvailableDate = oldTask.InstructionsAvailableDate.Value.AddDays(daysToShift); db.Tasks.Add(newTask); db.SaveChanges(); // store to remap the tasks below newTasks.Add(newTask); taskMap.Add(oldTask.TaskID, newTask.TaskID); } // go back and remap the related tasks List<int> newTaskIds = taskMap.Values.ToList(); foreach(Task newTask in newTasks) { if (newTask.RelatedTaskID > 0 && taskMap.ContainsKey(newTask.RelatedTaskID)) { newTask.RelatedTaskID = taskMap[newTask.RelatedTaskID]; } } db.SaveChanges(); } // FILES foreach (CourseFileGroup oldGroup in oldCourse.CourseFileGroups) { CourseFileGroup newGroup = new CourseFileGroup() { CourseID = newCourse.CourseID, Name = oldGroup.Name, SortOrder = oldGroup.SortOrder }; db.CourseFileGroups.Add(newGroup); db.SaveChanges(); foreach (CourseFileAssociation oldFile in oldGroup.CourseFileAssociations) { CourseFileAssociation newFile = new CourseFileAssociation() { GroupID = newGroup.GroupID, FileID = oldFile.FileID, DateAdded = newCourse.StartDate, IsActive = oldFile.IsActive, SortOrder = oldFile.SortOrder }; db.CourseFileAssociations.Add(newFile); } db.SaveChanges(); } return newCourse; }