public string[] CreateAnnouncement(string courseId, string userUuid, Dictionary <string, object> licenseSettings, string announcementTitle, string announcementMessage) { string error; var courseIdFixed = string.Format("_{0}_1", courseId); var client = BeginBatch(out error, licenseSettings); CourseMembershipWrapper membershipWS = client.getCourseMembershipWrapper(); var membershipFilter = new MembershipFilter { filterType = 2, filterTypeSpecified = true, courseIds = new[] { courseIdFixed }, }; var enrollments = membershipWS.loadCourseMembership(courseIdFixed, membershipFilter); var userWS = client.getUserWrapper(); var courseUsersFilter = new UserFilter { filterTypeSpecified = true, filterType = 2, id = enrollments.Select(x => x.userId).ToArray(), }; var courseUsers = userWS.getUser(courseUsersFilter); var uuidString = "USER.UUID=" + userUuid; var user = courseUsers.FirstOrDefault(cu => cu != null && cu.expansionData != null && cu.expansionData.Any(ed => string.Compare(uuidString, ed, StringComparison.OrdinalIgnoreCase) == 0)); if (user == null) { var adminRoles = new[] { "SYSTEM_ADMIN", "COURSE_CREATOR" }; user = courseUsers.FirstOrDefault(x => x.systemRoles.Any(role => adminRoles.Contains(role))); } if (user != null) { var announcementVO = new AnnouncementVO { body = announcementMessage, creatorUserId = user.id, courseId = courseIdFixed, permanent = true, permanentSpecified = true, position = 1, positionSpecified = true, pushNotify = true, pushNotifySpecified = true, title = announcementTitle, }; var annWS = client.getAnnouncementWrapper(); var results = annWS.saveCourseAnnouncements(courseIdFixed, new[] { announcementVO }); return(results); } return(null); }
public AnnouncementVO GetOneAnnouncement(long id) { var ann = _context.Announcements.FirstOrDefault(a => a.AnnouncementId == id); if (ann == null) { return(null); } var userType = _context.Users.Find(ann.UserId).UserType; if (userType != 2) { return(null); } var announce = new AnnouncementVO { AnnouncementId = id, Title = ann.Title, Content = ann.Content, Time = ann.Time }; return(announce); }