/// <summary> /// Adds notification to the db, /// and calls emailNotification if recipient's /// settings request notification emails. /// </summary> /// <param name="n">Notification to be added</param> private void addNotification(Notification n) { try { db.Notifications.Add(n); db.SaveChanges(); // Find recipient profile and check notification settings CourseUser recipient = (from a in db.CourseUsers where a.ID == n.RecipientID select a).FirstOrDefault(); bool isObserver = recipient.AbstractRoleID == (int)CourseRole.CourseRoles.Observer ? true : false; #if !DEBUG //If the recipient wants to receive e-mail notifications and they are not an Observer, send them an e-mail notification if (recipient.UserProfile.EmailAllNotifications && !isObserver) { emailNotification(n); } #endif } catch (Exception e) { //possibly null sender or recipient //TODO: address why we might get null } }
/// <summary> /// Builds and returns an XML listing for all the files in the path. All attributes /// are included with each file. /// Format example: /// <file_list> /// <file name="whatever.ext"> /// (all attributes in here) /// </file> /// </file_list> /// </summary> public string GetXMLListing(CourseUser courseUser, bool recurse = false) { // Determine what permissions this user has, since permission attributes // will be put in the listing. bool canDeleteFolders; if (null == courseUser) { canDeleteFolders = false; } else { canDeleteFolders = courseUser.AbstractRole.CanModify; } StringBuilder sb = new StringBuilder("<file_list>"); // We'll have a folder node for the root sb.AppendFormat("<folder name=\"/\" can_delete=\"{0}\" can_upload_to=\"{0}\">", canDeleteFolders.ToString()); GetXMLListing(courseUser, m_dataDir, recurse, sb); sb.Append("</folder></file_list>"); return(sb.ToString()); }
public async Task <IActionResult> PutCourseUser(Guid Courseid, CourseUser courseUser) { if (Courseid != courseUser.CourseId) { return(BadRequest()); } _context.Entry(courseUser).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CourseUserExists(Courseid, courseUser.LMSUserId)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public ActionResult CourseSetup(Course clone) { Course oldCourse = (Course)(from c in db.AbstractCourses where c.ID == clone.ID select c).FirstOrDefault(); Course getNewId = new Course(); clone.ID = getNewId.ID; CourseController cc = new CourseController(); if (ModelState.IsValid) { db.Courses.Add(clone); db.SaveChanges(); clone.TimeZoneOffset = Convert.ToInt32(Request.Params["course_timezone"]); cc.createMeetingTimes(clone, clone.TimeZoneOffset); cc.createBreaks(clone); // Make current user an instructor on new course. CourseUser cu = new CourseUser(); cu.AbstractCourseID = clone.ID; cu.UserProfileID = CurrentUser.ID; cu.AbstractRoleID = (int)CourseRole.CourseRoles.Instructor; db.CourseUsers.Add(cu); db.SaveChanges(); Cache["ActiveCourse"] = clone.ID; return(RedirectToAction("SelectAssignmentsToClone", new { courseID = oldCourse.ID })); } return(View(clone)); }
public void SendMailNotification(Mail mail) { // Send notification to recipient about new message. Notification n = new Notification(); n.ItemType = Notification.Types.Mail; n.ItemID = mail.ID; CourseUser recipient = db.CourseUsers.FirstOrDefault(cu => cu.UserProfileID == mail.ToUserProfileID && cu.AbstractCourseID == mail.ContextID); //CourseUser recipient = db.CourseUsers.FirstOrDefault(cu => cu.UserProfileID == mail.ToUserProfileID); //FLAG THIS LINE if (recipient != null) { n.RecipientID = recipient.ID; } CourseUser sender = db.CourseUsers.FirstOrDefault(cu => cu.UserProfileID == mail.FromUserProfileID && cu.AbstractCourseID == mail.ContextID); //CourseUser sender = db.CourseUsers.FirstOrDefault(cu => cu.UserProfileID == mail.FromUserProfileID); if (sender != null) { n.SenderID = sender.ID; } //using the data variable to store context id for email context later. n.Data = mail.ContextID.ToString(); addNotification(n); }
public ActionResult DeletePost(int id) { DashboardPost dp = db.DashboardPosts.Find(id); if (dp != null) { CourseUser cu = currentCourses.FirstOrDefault(c => c.AbstractCourseID == dp.CourseUser.AbstractCourseID); if ((dp.CourseUserID == ActiveCourseUser.ID) || ((cu != null) && (cu.AbstractRole.CanGrade))) { dp.Replies.Clear(); db.SaveChanges(); db.DashboardPosts.Remove(dp); db.SaveChanges(); } else { Response.StatusCode = 403; } } else { Response.StatusCode = 403; } return(View("_AjaxEmpty")); }
public void Insert(CourseUser model) { model.ID = new aers_sys_seedSqlMapDao().GetMaxID("CourseUser"); String stmtId = "CourseUser_Insert"; // Message_Insert ExecuteInsert(stmtId, model); }
public HttpResponseMessage Add(HttpRequestMessage request, CourseUserViewModel post) { return(CreateHttpResponse(request, () => { HttpResponseMessage response = null; if (!ModelState.IsValid) { response = request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } else { CourseUser newPost = new CourseUser(); newPost.UpdateCourseUser(post); newPost.CreatedDate = DateTime.Now; newPost.CreatedBy = User.Identity.Name; _courseUserService.CreateCourseUser(newPost); _courseUserService.SaveCourseUser(); // Update view model post = Mapper.Map <CourseUser, CourseUserViewModel>(newPost); response = request.CreateResponse <CourseUserViewModel>(HttpStatusCode.Created, post); } return response; })); }
// po kliknuti na startstudy ze z uzivatele stane student public async Task <IActionResult> IsStudent(int?id) { ApplicationUser user = await GetCurrentUserAsync(); await _userExtensions.CreateRoleAddToUser("StudentCourse" + id, user); //student kurzu await _userExtensions.CreateRoleAddToUser("Student", user); // pokud studuje alespon jeden kurz // seznam kurzu studenta var currentCourseId = await _context.Course.Where(x => x.Id == id).Select(x => x.Id).FirstOrDefaultAsync(); var userid = user.Id; CourseUser model = new CourseUser(); model.UserId = userid; model.CourseId = currentCourseId; var courseUserList = _context.CourseUser.Add(model); _context.Update(user); await _context.SaveChangesAsync(); await _signInManager.RefreshSignInAsync(user); await _context.SaveChangesAsync(); return(RedirectToAction("Details", new { Id = id })); }
public void UnSubscribe(int vakcode, ApplicationUser user) { var vak = db.Course.Find(vakcode); var cu = from cus in db.CourseUser where cus.ApplicationUserId == user.Id where cus.CourseId == vak.Id select cus; CourseUser courseUser = cu.FirstOrDefault(); if (vak == null || user == null || courseUser == null) { throw new ArgumentException("Het vak of de gebruiker dat werd meegegeven, is verkeerd meegegeven."); } var CMUL = from cmus in db.CourseMomentUsers join cm in db.CourseMoment on cmus.CoursMomentId equals cm.Id join c in db.Course on cm.CourseId equals c.Id where cmus.ApplicationUserId == user.Id where c.Id == vak.Id select cmus; foreach (var cmu in CMUL) { db.CourseMomentUsers.Remove(cmu); } db.SaveChanges(); db.CourseUser.Remove(courseUser); db.SaveChanges(); }
public bool IsVisibleTo(UserProfile currentUser, CourseUser activeCourse) { // If the course is an assessment committee... if (activeCourse.AbstractCourse is AssessmentCommittee) { return(null != activeCourse && ShownInAssessmentCommittees); } if (((currentUser != null) && (!AdminOnly || currentUser.IsAdmin)) && (!ModifierOnly || ((activeCourse != null) && activeCourse.AbstractRole.CanModify)) && (!GraderOnly || ((activeCourse != null) && activeCourse.AbstractRole.CanGrade)) && (!ViewerOnly || ((activeCourse != null) && activeCourse.AbstractRole.CanSeeAll)) && ((!CommunityOnlyPage && !NotInCommunityPage) || (NotInCommunityPage && activeCourse != null && !(activeCourse.AbstractCourse is Community) || (CommunityOnlyPage && activeCourse != null && activeCourse.AbstractCourse is Community))) ) { return(!ShownInAssessmentCommitteesOnly); } return(false); }
public async Task <IActionResult> CompleteLesson(int id) { var user = await GetCurrentUserAsync(); string userId = user.Id; int courseid = _context.Lesson.Where(x => x.Id == id).Select(x => x.Course.Id).FirstOrDefault(); // pridani poctu hotovych lekci do courseuser CourseUser originalCourse = await _context.CourseUser.Where(x => x.CourseId == courseid && x.UserId == userId).FirstOrDefaultAsync(); originalCourse.NumberOfFinishedLessons = originalCourse.NumberOfFinishedLessons + 1; //pridani hotovych lekci do FinishedUserLesson var lessonId = _context.Lesson.Where(x => x.Id == id).Select(x => x.Id).FirstOrDefault(); //pridani role FinishedLesson await _userExtensions.CreateRoleAddToUser("FinishedLesson" + id, user); FinishedUserLesson polozkaLessonUser = new FinishedUserLesson(); polozkaLessonUser.LessonId = lessonId; polozkaLessonUser.UserId = userId; polozkaLessonUser.CourseId = originalCourse.CourseId; _context.Update(originalCourse); _context.Add(polozkaLessonUser); await _context.SaveChangesAsync(); return(RedirectToAction("DetailsFinishedLesson", "Lessons", new { id = lessonId })); }
public DirectoryListing GetFileList(int courseId, string authToken) { //only continue if we have a valid authentication key if (!IsValidKey(authToken)) { return(new DirectoryListing()); } //pull the current user for easier access UserProfile currentUser = activeSessions[authToken].UserProfile; //find the current course CourseUser cu = (from c in db.CourseUsers where c.AbstractCourseID == courseId && c.UserProfileID == currentUser.ID select c).FirstOrDefault(); if (cu != null) { if (cu.AbstractRole.CanModify || cu.AbstractRole.CanUploadFiles == true) { return(FileSystem.GetCourseDocumentsFileList(cu.AbstractCourse as AbstractCourse, true)); } } return(new DirectoryListing()); }
private static bool VerifyModifyPermissions(HttpContext context, Models.Users.UserProfile up, int courseID) { OSBLEContext _db = new OSBLEContext(); CourseUser courseUser = ( from cu in _db.CourseUsers where cu.UserProfileID == up.ID && cu.AbstractCourse is AbstractCourse && cu.AbstractCourseID == courseID select cu ).FirstOrDefault(); if (null == courseUser || !courseUser.AbstractRole.CanModify) { // User cannot modify this course WriteErrorResponse(context, "The specified user does not have permission to modify course with ID=" + courseID.ToString() + "."); return(false); } return(true); }
public void SendUserTagNotifications(CourseUser sender, int postId, List <CourseUser> recipients, bool isAnonymous = false) { try { foreach (CourseUser recipient in recipients) { Notification n = new Notification(); n.ItemType = Notification.Types.UserTag; n.ItemID = postId; n.RecipientID = recipient.ID; if (sender != null) { n.SenderID = sender.ID; } if (isAnonymous) { n.Data = "IsAnonymous"; } addNotification(n); } } catch { // against Dan's better judgement, do nothing!!!! } }
public StudentTeamEvalSubmissionDecorator(IHeaderBuilder builder, List <TeamEvaluation> teamEvals, CourseUser student) : base(builder) { TeamEvals = teamEvals; Student = student; }
public void GetStudentRequestsTest() { // ARRANGE LectorService service = new LectorService(ctxDb); ApplicationUser user1 = new ApplicationUser { UserName = "******", Email = "*****@*****.**", GeboorteDatum = new DateTime(1998, 09, 21), Naam = "Cleas", VoorNaam = "Thomas", EmailConfirmed = true }; ApplicationUser user2 = new ApplicationUser { UserName = "******", Email = "*****@*****.**", GeboorteDatum = new DateTime(1998, 09, 21), Naam = "Haesevoets", VoorNaam = "Jaimie", EmailConfirmed = true }; ApplicationUser user3 = new ApplicationUser { UserName = "******", Email = "*****@*****.**", GeboorteDatum = new DateTime(1998, 09, 21), Naam = "VanBeal", VoorNaam = "Rik", EmailConfirmed = true }; ctxDb.Users.Add(user1); ctxDb.Users.Add(user2); ctxDb.Users.Add(user3); ctxDb.SaveChanges(); string userId1 = ctxDb.Users.Where(u => u.UserName == "r0664186").FirstOrDefault().Id; string userId2 = ctxDb.Users.Where(u => u.UserName == "r1234567").FirstOrDefault().Id; string userId3 = ctxDb.Users.Where(u => u.UserName == "r2345678").FirstOrDefault().Id; Course course = new Course { Vakcode = "MGP01A", Titel = "front end", Studiepunten = 6, FieldOfStudyId = 123 }; ctxDb.Course.Add(course); ctxDb.SaveChanges(); int courseId1 = ctxDb.Course.Where(c => c.Vakcode == "MGP01A").FirstOrDefault().Id; CourseUser cu1 = new CourseUser { ApplicationUserId = userId1, CourseId = courseId1, GoedGekeurd = false }; CourseUser cu2 = new CourseUser { ApplicationUserId = userId2, CourseId = courseId1, GoedGekeurd = true }; CourseUser cu3 = new CourseUser { ApplicationUserId = userId3, CourseId = courseId1, GoedGekeurd = false }; ctxDb.CourseUser.Add(cu1); ctxDb.CourseUser.Add(cu2); ctxDb.CourseUser.Add(cu3); ctxDb.SaveChanges(); // ACT var requests = service.GetStudentRequests(); // ASSERT Assert.IsTrue(requests.Count == 2); for (int i = 1; i < requests.Count; i++) { Assert.IsTrue(requests[i].RNum == user1.UserName || requests[i].RNum == user3.UserName); } }
public bool PostActivityMessage(string message, int courseId, string authToken) { //validate the user if (!IsValidKey(authToken)) { return(false); } //because "currentUser" was pulled from a previous DB context, we need //to repull using the current context int profileId = activeSessions[authToken].UserProfile.ID; UserProfile currentUser = (from u in db.UserProfiles where u.ID == profileId select u).FirstOrDefault(); if (currentUser == null) { return(false); } //find the course Course course = (from c in db.Courses where c.ID == courseId select c).FirstOrDefault(); if (course == null) { return(false); } CourseUser courseUser = (from cu in db.CourseUsers where cu.UserProfileID == currentUser.ID && cu.AbstractCourseID == course.ID select cu ).FirstOrDefault(); if (courseUser == null) { return(false); } //use the data provided to create a new dashboard post DashboardPost newDp = new DashboardPost(); newDp.Content = message; newDp.Posted = DateTime.UtcNow; newDp.CourseUser = courseUser; //add & save db.DashboardPosts.Add(newDp); db.SaveChanges(); //return success return(true); }
public bool SubmitAssignment(int assignmentId, byte[] zipData, string authToken) { if (!_authService.IsValidKey(authToken)) { return(false); } try { Assignment assignment = _db.Assignments.Find(assignmentId); UserProfile user = _authService.GetActiveUser(authToken); CourseUser courseUser = _db.CourseUsers .Where(cu => cu.AbstractCourseID == assignment.CourseID) .Where(cu => cu.UserProfileID == user.ID) .FirstOrDefault(); Team team = (from tm in _db.TeamMembers join at in _db.AssignmentTeams on tm.TeamID equals at.TeamID where tm.CourseUserID == courseUser.ID && at.AssignmentID == assignmentId select tm.Team).FirstOrDefault(); OSBLE.Models.FileSystem.AssignmentFilePath fs = Models.FileSystem.Directories.GetAssignment( (int)assignment.CourseID, assignmentId); MemoryStream ms = new MemoryStream(zipData); ms.Position = 0; using (ZipFile file = ZipFile.Read(ms)) { foreach (ZipEntry entry in file.Entries) { MemoryStream extractStream = new MemoryStream(); entry.Extract(extractStream); extractStream.Position = 0; //delete existing fs.Submission(team.ID) .File(entry.FileName) .Delete(); //add the extracted file to the file system bool result = fs.Submission(team.ID) .AddFile(entry.FileName, extractStream); if (result == false) { return(false); } } } } catch (Exception) { return(false); } return(true); }
public bool SubmitReview(int authorId, int assignmentId, byte[] zippedReviewData, string authToken) { if (!_authService.IsValidKey(authToken)) { return(false); } try { UserProfile profile = _authService.GetActiveUser(authToken); Assignment assignment = _db.Assignments.Find(assignmentId); CourseUser courseUser = (from cu in _db.CourseUsers where cu.AbstractCourseID == assignment.CourseID && cu.UserProfileID == profile.ID select cu).FirstOrDefault(); Team reviewTeam = (from tm in _db.TeamMembers join rt in _db.ReviewTeams on tm.TeamID equals rt.ReviewTeamID where tm.CourseUserID == courseUser.ID && rt.AssignmentID == assignmentId select tm.Team).FirstOrDefault(); MemoryStream ms = new MemoryStream(zippedReviewData); ms.Position = 0; using (ZipFile file = ZipFile.Read(ms)) { foreach (ZipEntry entry in file.Entries) { using (MemoryStream extractStream = new MemoryStream()) { entry.Extract(extractStream); extractStream.Position = 0; // Get the storage object for the review OSBLEDirectory fs = Models.FileSystem.Directories.GetReview( (int)assignment.CourseID, assignmentId, authorId, reviewTeam.ID); // Delete existing first fs.DeleteContents(true, true); //add the extracted file to the file system bool result = fs.AddFile(entry.FileName, extractStream); if (result == false) { return(false); } } } } } catch (Exception) { return(false); } return(true); }
public async Task <ServiceResponse <GetCourseDto> > AddInstructorToCourse(int userId, int courseId) { ServiceResponse <GetCourseDto> serviceResponse = new ServiceResponse <GetCourseDto>(); User dbUser = await _context.Users .Include(c => c.InstructedCourses) .FirstOrDefaultAsync(c => c.Id == userId); Course dbCourse = await _context.Courses .Include(c => c.Instructors).ThenInclude(cs => cs.User) .Include(c => c.Sections) .FirstOrDefaultAsync(c => c.Id == courseId); if (dbCourse == null) { serviceResponse.Success = false; serviceResponse.Message = "Course not found."; return(serviceResponse); } if (dbUser == null) { serviceResponse.Success = false; serviceResponse.Message = "User not found."; return(serviceResponse); } if (!dbCourse.Instructors.Any(c => c.UserId == GetUserId())) { serviceResponse.Success = false; serviceResponse.Message = "User does not have authority on this course."; return(serviceResponse); } if (dbCourse.Instructors.Any(c => c.UserId == userId)) { serviceResponse.Success = false; serviceResponse.Message = "User already an instructor/TA in this course."; return(serviceResponse); } CourseUser newInstructor = new CourseUser { User = dbUser, UserId = dbUser.Id, Course = dbCourse, CourseId = dbCourse.Id }; dbCourse.Instructors.Add(newInstructor); _context.Courses.Update(dbCourse); await _context.SaveChangesAsync(); serviceResponse.Data = await AddExtraDtos(_mapper.Map <GetCourseDto>(dbCourse)); return(serviceResponse); }
public void GetStudAlreadySubscribedTest() { // ARRANGE /*the commented area is to check if functions returns -1 when there isn't a fos*/ FieldOfStudyService service = new FieldOfStudyService(ctxDb); ApplicationUser user = new ApplicationUser { UserName = "******", Email = "*****@*****.**", GeboorteDatum = new DateTime(1998, 09, 21), Naam = "Claes", VoorNaam = "Thomas", EmailConfirmed = true }; ctxDb.Users.Add(user); ctxDb.SaveChanges(); string userId = ctxDb.Users.Where(u => u.UserName == "r0664186").FirstOrDefault().Id; FieldOfStudy fos = new FieldOfStudy { RichtingCode = "MGP", RichtingTitel = "model graduaat programmeren", Type = "graduaat" }; ctxDb.FieldOfStudy.Add(fos); ctxDb.SaveChanges(); int fosId = ctxDb.FieldOfStudy.Where(fos => fos.RichtingCode == "MGP").FirstOrDefault().Id; Course course = new Course { Vakcode = "MGP01A", Titel = "front end", Studiepunten = 6, FieldOfStudyId = fosId }; ctxDb.Course.Add(course); //Course course1 = new Course { Vakcode = "MBP01A", Titel = "front end", Studiepunten = 8}; //ctxDb.Course.Add(course1); ctxDb.SaveChanges(); int courseId = ctxDb.Course.Where(c => c.Vakcode == "MGP01A").FirstOrDefault().Id; //int course1Id = ctxDb.Course.Where(c => c.Vakcode == "MBP01A").FirstOrDefault().Id; CourseUser cu = new CourseUser { ApplicationUserId = userId, CourseId = courseId }; ctxDb.CourseUser.Add(cu); //CourseUser cu1 = new CourseUser { ApplicationUserId = userId, CourseId = course1Id}; //ctxDb.CourseUser.Add(cu1); ctxDb.SaveChanges(); // ACT int reqFosId = service.GetStudAlreadySubscribed(ctxDb.Users.Find(userId)); // ASSERT Assert.AreEqual(fosId, reqFosId); }
public byte[] GetAssignmentSubmission(int assignmentId, string authToken) { if (!_authService.IsValidKey(authToken)) { return(new byte[0]); } UserProfile profile = _authService.GetActiveUser(authToken); Assignment assignment = _db.Assignments.Find(assignmentId); //make sure that the user is enrolled in the course CourseUser courseUser = (from cu in _db.CourseUsers where cu.AbstractCourseID == assignment.CourseID && cu.UserProfileID == profile.ID select cu).FirstOrDefault(); if (courseUser == null) { return(new byte[0]); } //users are attached to assignments through teams, so we have to find the correct team Team team = (from tm in _db.TeamMembers join at in _db.AssignmentTeams on tm.TeamID equals at.TeamID where tm.CourseUserID == courseUser.ID && at.AssignmentID == assignmentId select tm.Team).FirstOrDefault(); if (team == null) { return(new byte[0]); } OSBLE.Models.FileSystem.AssignmentFilePath fs = Models.FileSystem.Directories.GetAssignment( courseUser.AbstractCourseID, assignmentId); Stream stream = fs.Submission(team.ID) .AllFiles() .ToZipStream(); MemoryStream ms = new MemoryStream(); try { stream.CopyTo(ms); } catch (Exception) { } byte[] bytes = ms.ToArray(); stream.Close(); ms.Close(); return(bytes); }
public void Subscribe(int vakCode, ApplicationUser user) { var vak = db.Course.Find(vakCode); CourseUser cu = new CourseUser { CourseId = vak.Id, ApplicationUserId = user.Id, GoedGekeurd = false }; db.CourseUser.Add(cu); db.SaveChanges(); }
//[Authorize] public async Task <IActionResult> Create(CourseVM courseVM) { courseVM.Categories = await _dbContext.Categories.ToListAsync(); Course course = new Course(); var user = await _dbContext.Users.SingleOrDefaultAsync(x => _userManager.FindByNameAsync(User.Identity.Name).GetAwaiter().GetResult().Id == x.Id); if (courseVM.Course.IsFree != true) { if (courseVM.Course.Amount == 0) { ModelState.AddModelError("Course.Amount", "Boş ola bilməz!!!"); return(View(courseVM)); } course.Amount = courseVM.Course.Amount; } if (courseVM.Course.Photo == null) { ModelState.AddModelError("Course.Photo", "Boş ola bilməz!!!"); return(View(courseVM)); } if (!courseVM.Course.Photo.IsImage()) { ModelState.AddModelError("Course.Photo", "Fayl şəkil tipində olmalıdır!!!"); return(View(courseVM)); } string image = await courseVM.Course.Photo.SaveAsync(_env.WebRootPath, "images", "courses"); course.CategoryId = courseVM.CategoryId; course.Content = courseVM.Course.Content; course.IsFree = courseVM.Course.IsFree; course.Image = image; course.PublishDate = DateTime.Now; course.Title = courseVM.Course.Title; await _dbContext.AddAsync(course); CourseUser courseUser = new CourseUser { AppUserId = user.Id, CourseId = course.ID, IsAuthor = true }; await _dbContext.AddAsync(courseUser); await _dbContext.SaveChangesAsync(); return(RedirectToAction(nameof(OwnCourses))); }
public void ClearTables() { var mockCourseData = new Course[] { }; var mockCourseUserData = new CourseUser[] { }; var mockNodeData = new Node[] { }; var mockNodeResourceData = new NodeResource[] { }; this._MockDataContext.SetupGet(c => c.Courses).Returns(new MemoryTable <Course>(mockCourseData)); this._MockDataContext.SetupGet(c => c.Nodes).Returns(new MemoryTable <Node>(mockNodeData)); this._MockDataContext.SetupGet(c => c.NodeResources).Returns(new MemoryTable <NodeResource>(mockNodeResourceData)); this._MockDataContext.SetupGet(c => c.CourseUsers).Returns(new MemoryTable <CourseUser>(mockCourseUserData)); }
public IActionResult SingOutUser(CourseUser model) { if (model.CourseId == 0 || model.UserId == null) { return(RedirectToAction(nameof(All))); } this.courseService.SingOutUser(model); this.TempData.AddSuccessMessage("Sing out is successful."); return(RedirectToAction(nameof(All))); }
/// <summary> /// Returns true if the posters name should be Anonymized for a discussion assignment /// </summary> /// <param name="currentUser">The current users</param> /// <param name="poster">The posters courseuser</param> /// <param name="discussionSetting">The assignments discussion settings</param> /// <returns></returns> public static bool AnonymizeNameForDiscussion(CourseUser poster, CourseUser currentUser, DiscussionSetting discussionSettings) { bool Anonymous = false; //Don't want to set anonymous permissions if the poster is the current user //Additionally, we do not want to anonmize for TA or Instructors if (poster.ID != currentUser.ID && currentUser.AbstractRoleID != (int)CourseRole.CourseRoles.Instructor && currentUser.AbstractRoleID != (int)CourseRole.CourseRoles.TA) { //Checking role of currentUser bool currentUserIsStudent = currentUser.AbstractRoleID == (int)CourseRole.CourseRoles.Student; bool currentUserIsModerator = currentUser.AbstractRoleID == (int)CourseRole.CourseRoles.Moderator; bool currentUserIsObserver = currentUser.AbstractRoleID == (int)CourseRole.CourseRoles.Observer; //Checking role of poster. Note: If the poster is a TA, we treat them like a moderator or instructor depending on the value //of TAsCanPostToAllDiscussions bool posterIsStudent = poster.AbstractRoleID == (int)CourseRole.CourseRoles.Student; bool posterIsModerator = poster.AbstractRoleID == (int)CourseRole.CourseRoles.Moderator || (!discussionSettings.TAsCanPostToAllDiscussions && poster.AbstractRoleID == (int)CourseRole.CourseRoles.TA); bool posterIsInstructor = poster.AbstractRoleID == (int)CourseRole.CourseRoles.Instructor || (discussionSettings.TAsCanPostToAllDiscussions && poster.AbstractRoleID == (int)CourseRole.CourseRoles.TA); //if current user is a student, poster is a student, and student is anonymized to student if (discussionSettings.HasAnonymousStudentsToStudents && currentUserIsStudent && posterIsStudent) { Anonymous = true; } //if current user is a student, poster is an instructor, and instructor is anonymized to student else if (discussionSettings.HasAnonymousInstructorsToStudents && currentUserIsStudent && posterIsInstructor) { Anonymous = true; } //if current user is a student, poster is an moderator, and moderator is anonymized to student else if (discussionSettings.HasAnonymousModeratorsToStudents && currentUserIsStudent && posterIsModerator) { Anonymous = true; } //if current user is a moderator, poster is a student, and student is anonymized to moderator else if (discussionSettings.HasAnonymousStudentsToModerators && currentUserIsModerator && posterIsStudent) { Anonymous = true; } else if (currentUserIsObserver) { Anonymous = true; } } return(Anonymous); }
public async Task AddCourseUser(string CourseID, string LMSUserid) { var temp = new CourseUser { LMSUserId = LMSUserid }; temp.Course = await _context.Courses.FirstOrDefaultAsync(c => c.Id.ToString() == CourseID); temp.CourseId = temp.Course.Id; _context.Add(temp); // await _context.SaveChangesAsync(); }
public ActionResult GetReviewsOfAuthor(int assignmentId, int receiverId) { Assignment CRAssignment = db.Assignments.Find(assignmentId); CourseUser receiver = db.CourseUsers.Find(receiverId); AssignmentTeam AuthorTeam = GetAssignmentTeam(CRAssignment.PreceedingAssignment, receiver); if (ActiveCourseUser.AbstractRole.CanModify || (receiverId == ActiveCourseUser.ID)) { //No need to anonymize name AuthorTeam here as this function call is only made by Instructors and the author team. return(GetAllReviewedDocuments(CRAssignment, AuthorTeam.Team, "Critical Reviews for " + AuthorTeam.Team.Name + ".zip")); } return(RedirectToAction("Index", "Home")); }
public IEnumerable<CourseGetResponse> Get(string courseCode) { IEnumerable<Course> courses = _repCourse.Get(filter: u => (u.CourseCode == courseCode), includes: "Questionnaire,CourseUserRoles,GroupType"); List<CourseGetResponse> CourseGetResponses = new List<CourseGetResponse>(); foreach (Course course in courses) { CourseGetResponse dr = new CourseGetResponse() { CourseCode = course.CourseCode, CourseName = course.CourseName, QuestionnaireCode = course.Questionnaire.QuestionnaireCode, CourseDescription = course.CourseDescription, DesiredSkillSets = course.DesiredSkillSets, GroupSize = course.PrefGroupSize, GroupType = course.GroupType.GroupTypeCode, PreferSimiliarSkillSet = course.SimilarSkillSetPreffered, UserList = new List<CourseUser>(), CourseGroups = new List<CourseGroups>() }; foreach(var cur in course.CourseUserRoles) { CourseUser cu = new CourseUser() { EmailID = cur.UserProfile.EmailId, Name = cur.UserProfile.FirstName + " " + cur.UserProfile.LastName, RoleCode = cur.Role.RoleCode, }; if(cur.Group != null) { if (!dr.CourseGroups.Any(x => x.GroupCode == cur.Group.GroupCode)) { CourseGroups cg = new CourseGroups() { GroupCode = cur.Group.GroupCode, GroupName = cur.Group.GroupName, Objective = cur.Group.Objective, TimeZone = cur.Group.TimeZone }; dr.CourseGroups.Add(cg); } } dr.UserList.Add(cu); } CourseGetResponses.Add(dr); } return CourseGetResponses; }
public void ClearTables() { var mockCourseData = new Course[] { }; var mockCourseUserData = new CourseUser[] { }; var mockNodeData = new Node[] { }; var mockNodeResourceData = new NodeResource[] { }; this._MockDataContext.SetupGet(c => c.Courses).Returns(new MemoryTable<Course>(mockCourseData)); this._MockDataContext.SetupGet(c => c.Nodes).Returns(new MemoryTable<Node>(mockNodeData)); this._MockDataContext.SetupGet(c => c.NodeResources).Returns(new MemoryTable<NodeResource>(mockNodeResourceData)); this._MockDataContext.SetupGet(c => c.CourseUsers).Returns(new MemoryTable<CourseUser>(mockCourseUserData)); }