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 static void ClearUserCache(User user) { string key = string.Format(_usernameKey, user.Username); if (HttpContext.Current.Cache[key] != null) { HttpContext.Current.Cache.Remove(key); //HttpContext.Current.Cache[key] = null; } key = string.Format(_userIdKey, user.UserID); if (HttpContext.Current.Cache[key] != null) { HttpContext.Current.Cache.Remove(key); //HttpContext.Current.Cache[key] = null; } }
public static bool SyncCourse(int courseID, string sessionYear, string sessionCode, string courseCode, string section, string courseHours) { DidacheDb db = new DidacheDb(); bool success = false; Course course = db.Courses.Find(courseID); // get code from CARS List<CarsStudentUser> users = GetCarsData(sessionYear, sessionCode, courseCode, section, courseHours); List<CarsStudentUser> toRemove = users.Where(u => u.CarsUserStatus == CarsUserStatus.NotActive).ToList(); List<CarsStudentUser> toAdd = users.Where(u => u.CarsUserStatus == CarsUserStatus.Active).ToList(); // remove all droppies foreach (CarsStudentUser carsStudentUser in toRemove) { CourseUsers.RemoveUserFromCourse(courseID, carsStudentUser.UserID, CourseUserRole.Student); } // add all the 'R' foreach (CarsStudentUser carsStudentUser in toAdd) { User user = db.Users.Find(carsStudentUser.UserID); // check for user if (user == null) { // create login MembershipUser membershipUser = null; // try to find membershipUser = Membership.GetUser(carsStudentUser.UserID.ToString(), false); if (membershipUser == null) membershipUser = Membership.CreateUser(carsStudentUser.UserID.ToString(), carsStudentUser.UserID.ToString() + carsStudentUser.LastName.Substring(0, 1), carsStudentUser.Email); // create user user = new User() { UserID = carsStudentUser.UserID, FirstName = carsStudentUser.FirstName, MiddleName = carsStudentUser.MiddleName, LastName = carsStudentUser.LastName, Email = carsStudentUser.Email, NameFormat = carsStudentUser.NameFormat, Username = membershipUser.UserName, AspnetUserID = new Guid(membershipUser.ProviderUserKey.ToString()), BirthDate = null, DeceasedDate = null, LastUpdatedDate = DateTime.Now, IsDeceased = false, Language = "en-US", PersonID = Guid.Empty, IsRegistered = true, TimezoneOffset = -6, Hometown = "", AlmaMater = "", Bio = "", MinistryGoals = "", Facebook = "", Twitter = "", Website = "", AliasName = "", PictureSecurity = 0, AddressSecurity = 0, EmailSecurity = 0, PhoneSecurity = 0, SpouseSecurity = 1, ChildrenSecurity = 1, BiographySecurity = 0, ScheduleSecurity = 1, BirthdateSecurity = 1 }; db.Users.Add(user); //try { db.SaveChanges(); //} catch (Exception ex) { //} } CourseUsers.AddUserToCourse(courseID, user.UserID, -1, CourseUserRole.Student); } //CourseUsers.RemoveUserFromCourse(courseID, userID, (CourseUserRole)roleID); //CourseUsers.AddUserToCourse(courseID, userID, groupID, (CourseUserRole)roleID); return success; }