public virtual async Task <OperationResult> Edit([FromBody] EditSeminarDto model) { if (string.IsNullOrWhiteSpace(model.SeminarLicenseId)) { throw new ArgumentException("seminarLicenseId can't be empty", nameof(model.SeminarLicenseId)); } try { LtiParamDTO param = Session.LtiSession.LtiParam; var trace = new StringBuilder(); var fb = new SeminarFolderBuilder(model.SeminarLicenseId); OperationResult ret = await MeetingSetup.SaveMeeting( LmsCompany, GetUserProvider(), param, model, trace, fb); return(TrickForSeminar(ret, model.SeminarLicenseId)); } catch (Exception ex) { string errorMessage = GetOutputErrorMessage("Edit", ex); return(OperationResult.Error(errorMessage)); } }
private async Task CreateCalendarEvents(LtiParamDTO param, LmsCourseMeeting meeting) { if (_calendarEventService == null) { return; } foreach (var session in meeting.MeetingSessions) { var eventDto = new LmsCalendarEventDTO { StartAt = session.StartDate, EndAt = session.EndDate, Title = session.Name }; var lmsSettings = _license.GetLMSSettings(Settings); try { LmsCalendarEventDTO lmsCalendarEvent = await _calendarEventService.CreateEvent(param.course_id.ToString(), lmsSettings, eventDto); session.LmsCalendarEventId = lmsCalendarEvent?.Id; } catch (Exception e) { _logger.Error(e.Message); return; } } }
public async Task <MeetingSessionDTO> CreateSessionAsync(int meetingId, LtiParamDTO param) { //LmsCourseMeeting meeting = _lmsCourseMeetingModel.GetOneById(meetingId).Value; //MeetingNameInfo nameInfo = string.IsNullOrWhiteSpace(meeting.MeetingNameJson) // ? new MeetingNameInfo() // : JsonConvert.DeserializeObject<MeetingNameInfo>(meeting.MeetingNameJson); //var lastEvent = meeting.MeetingSessions.OrderByDescending(x => x.StartDate).FirstOrDefault(); DateTime startDate = DateTime.UtcNow.AddHours(1); DateTime endDate = startDate.AddHours(1); //if (lastEvent != null) //{ // startDate = lastEvent.StartDate.AddDays(1); // endDate = lastEvent.EndDate.AddDays(1); //} var ev = new MeetingSessionDTO { //Name = nameInfo.meetingName + " #", Summary = string.Empty, StartDate = startDate, EndDate = endDate, }; if (_calendarExportService != null) { var session = await _calendarExportService.SaveEventsAsync(meetingId, new MeetingSessionDTO[] { ev }, param, _license); return(session.Single()); } return(ev); }
public async Task <MeetingSessionDTO> CreateSessionAsync(int meetingId, LtiParamDTO param) { LmsCourseMeeting meeting = _lmsCourseMeetingModel.GetOneById(meetingId).Value; MeetingNameInfo nameInfo = string.IsNullOrWhiteSpace(meeting.MeetingNameJson) ? new MeetingNameInfo() : JsonConvert.DeserializeObject <MeetingNameInfo>(meeting.MeetingNameJson); var lastEvent = meeting.MeetingSessions.OrderByDescending(x => x.StartDate).FirstOrDefault(); DateTime startDate = DateTime.UtcNow.AddHours(1); DateTime endDate = startDate.AddHours(1); if (lastEvent != null) { startDate = lastEvent.StartDate.AddDays(1); endDate = lastEvent.EndDate.AddDays(1); } var ev = new MeetingSessionDTO { Name = nameInfo.meetingName + " #", Summary = string.Empty, StartDate = startDate, EndDate = endDate, }; if (_calendarExportService != null) { var sakaiEventResult = await _calendarExportService.SaveEventsAsync(meetingId, new MeetingSessionDTO[] { ev }, param, _license); ev = sakaiEventResult.Single(); } var dbEvent = new LmsMeetingSession { LmsCalendarEventId = ev.EventId, Name = ev.Name, StartDate = ev.StartDate, EndDate = ev.EndDate, LmsCourseMeeting = meeting, }; if (_calendarEventService != null) { var lmsSettings = _license.GetLMSSettings(Settings); LmsCalendarEventDTO calendarEventDto = new LmsCalendarEventDTO() { Title = dbEvent.Name, StartAt = dbEvent.StartDate, EndAt = dbEvent.EndDate }; LmsCalendarEventDTO newClaendarEventDto = await _calendarEventService.CreateEvent(param.course_id.ToString(), lmsSettings, calendarEventDto); dbEvent.LmsCalendarEventId = newClaendarEventDto?.Id; } meeting.MeetingSessions.Add(dbEvent); _lmsCourseMeetingModel.RegisterSave(meeting, true); return(ConvertFromEntity(dbEvent)); }
public BridgeMeetingSessionService(LmsCourseMeetingModel lmsCourseMeetingModel, ILogger logger, ICalendarExportService calendarExportService, IBridgeApi api, ILmsLicense license, LtiParamDTO param) { _lmsCourseMeetingModel = lmsCourseMeetingModel ?? throw new ArgumentNullException(nameof(lmsCourseMeetingModel)); _logger = logger ?? throw new ArgumentNullException(nameof(logger)); _calendarExportService = calendarExportService; _license = license; _param = param; _api = api; }
private string GetApiUrl(LtiParamDTO param) { var scheme = param.lis_outcome_service_url != null && param.lis_outcome_service_url.IndexOf(HttpScheme.Https, StringComparison.InvariantCultureIgnoreCase) >= 0 ? HttpScheme.Https : HttpScheme.Http; return($"{scheme}{param.lms_domain}/egcint/service/"); }
private void CreateAnnouncement( LmsMeetingType meetingType, ILmsLicense lmsCompany, LtiParamDTO param, MeetingDTO meetingDto, DateTime startDate) { if (!lmsCompany.ShowAnnouncements.GetValueOrDefault() || string.IsNullOrEmpty(param.context_title)) { return; } var announcementTitle = string.Format( "A new {0} room was created for course {1}", meetingNames[meetingType], param.context_title); string announcementMessage = GetAnnouncementMessage(meetingType, meetingDto, param.referer, startDate); switch (lmsCompany.LmsProviderId) { case (int)LmsProviderEnum.Canvas: var lmsUser = LmsUserModel.GetOneByUserIdAndCompanyLms(param.lms_user_id, lmsCompany.Id).Value; var token = UsersSetup.IsTeacher(param, lmsCompany) && !String.IsNullOrEmpty(lmsUser.Token) ? lmsUser.Token : lmsCompany.AdminUser.Return(a => a.Token, string.Empty); CanvasApi.CreateAnnouncement( lmsCompany.LmsDomain, token, param.course_id, announcementTitle, announcementMessage); break; case (int)LmsProviderEnum.Blackboard: BlackboardApi.CreateAnnouncement(param.course_id.ToString(), param.user_id, lmsCompany.GetLMSSettings(Settings), announcementTitle, announcementMessage); break; case (int)LmsProviderEnum.AgilixBuzz: // string error; // this.dlapApi.CreateAnnouncement( // credentials, // param.course_id, // announcementTitle, // announcementMessage, // out error); break; } }
public async Task <OperationResult> DeleteEvent([FromBody] DeleteMeetingEventDto model) { try { LtiParamDTO param = Session.LtiSession.LtiParam; var meetingSessionService = _lmsFactory.GetMeetingSessionService(LmsCompany, param); await meetingSessionService.DeleteSessionAsync(model.MeetingId, model.Id.GetValueOrDefault(), param); return(OperationResult.Success()); } catch (Exception ex) { string errorMessage = GetOutputErrorMessage("DeleteSession", ex); return(OperationResult.Error(errorMessage)); } }
public async Task <OperationResultWithData <IEnumerable <MeetingSessionDTO> > > GetEvents([FromBody] MeetingRequestDto request) { try { LtiParamDTO param = Session.LtiSession.LtiParam; var meetingSessionService = _lmsFactory.GetMeetingSessionService(LmsCompany, param); var result = await meetingSessionService.GetSessions(request.MeetingId); return(result.ToSuccessResult()); } catch (Exception ex) { string errorMessage = GetOutputErrorMessage("GetSessions", ex); return(OperationResultWithData <IEnumerable <MeetingSessionDTO> > .Error(errorMessage)); } }
public async Task <OperationResultWithData <MeetingSessionDTO> > CreateEvent([FromBody] CreateEventDto model) { try { LtiParamDTO param = Session.LtiSession.LtiParam; var meetingSessionService = _lmsFactory.GetMeetingSessionService(LmsCompany, param); var eve = await meetingSessionService.CreateSessionAsync(model.MeetingId, param); return(eve.ToSuccessResult()); } catch (Exception ex) { string errorMessage = GetOutputErrorMessage("CreateSession", ex); return(OperationResultWithData <MeetingSessionDTO> .Error(errorMessage)); } }
private async Task UpdateCalendarEvent(MeetingSessionDTO dto, LtiParamDTO param, LmsMeetingSession dbEvent) { if (_calendarEventService != null) { if (!string.IsNullOrEmpty(dbEvent.LmsCalendarEventId)) { var lmsSettings = _license.GetLMSSettings(Settings); LmsCalendarEventDTO calendarEventDto = new LmsCalendarEventDTO { Id = dbEvent.LmsCalendarEventId, Title = dto.Name, StartAt = dto.StartDate, EndAt = dto.EndDate }; await _calendarEventService.UpdateEvent(param.course_id.ToString(), lmsSettings, calendarEventDto); } } }
private Principal GetPrincipal(ILmsLicense lmsCompany, LtiParamDTO param, string scoId, IAdobeConnectProxy provider, out string breezeToken) { breezeToken = string.Empty; var lmsUser = LmsUserModel.GetOneByUserIdAndCompanyLms(param.lms_user_id, lmsCompany.Id).Value; if (lmsUser == null) { throw new WarningMessageException(string.Format("No user with id {0} found in the database.", param.lms_user_id)); } var loginResult = MeetingSetup.ACLogin(lmsCompany, param, lmsUser, provider); breezeToken = loginResult.BreezeSession; return(loginResult.User); }
public virtual async Task <OperationResultWithData <IEnumerable <MeetingDTO> > > GetCourseMeetings() { StringBuilder trace = null; var acProvider = this.GetAdminProvider(); var param = new LtiParamDTO { course_id = CourseId }; // TODO: implement. will be use be External API only IEnumerable <MeetingDTO> meetings = await _meetingSetup.GetMeetingsAsync( LmsCompany, acProvider, new LmsUser(), //session.LmsUser, param, trace, true); return(meetings.ToSuccessResult()); }
public async Task <OperationResultWithData <MeetingSessionDTO> > SaveEvent([FromBody] SaveMeetingEventDto model) { if (!CheckStartTimeMoreCurrentTime(model.StartDate)) { return(OperationResultWithData <MeetingSessionDTO> .Error("Start time should be more then current time")); } try { LtiParamDTO param = Session.LtiSession.LtiParam; var meetingSessionService = _lmsFactory.GetMeetingSessionService(LmsCompany, param); var eve = await meetingSessionService.SaveSessionAsync(model.MeetingId, model, param); return(eve.ToSuccessResult()); } catch (Exception ex) { string errorMessage = GetOutputErrorMessage("SaveSession", ex); return(OperationResultWithData <MeetingSessionDTO> .Error(errorMessage)); } }
public async Task <OperationResultWithData <IEnumerable <MeetingSessionDTO> > > CreateBatch([FromBody] CreateMeetingSessionsBatchDto dto) { try { if (!CheckStartTimeMoreCurrentTime(dto.StartTimestamp)) { return(OperationResultWithData <IEnumerable <MeetingSessionDTO> > .Error("Start time should be more then current time")); } LtiParamDTO param = Session.LtiSession.LtiParam; var meetingSessionService = _lmsFactory.GetMeetingSessionService(LmsCompany, param); var result = await meetingSessionService.CreateBatchAsync(dto, param); return(result.ToSuccessResult()); } catch (Exception ex) { string errorMessage = GetOutputErrorMessage("CreateBatchEvents", ex); return(OperationResultWithData <IEnumerable <MeetingSessionDTO> > .Error(errorMessage)); } }
public async Task DeleteSessionAsync(int meetingId, int id, LtiParamDTO param) { LmsCourseMeeting meeting = null; LmsMeetingSession dbEvent = null; if (meetingId != 0) { meeting = _lmsCourseMeetingModel.GetOneById(meetingId).Value; dbEvent = meeting.MeetingSessions.FirstOrDefault(x => x.Id == id); if (dbEvent == null) { throw new InvalidOperationException( $"Could not find meeting session in database. MeetingId={meetingId}, Id={id}"); } } if (_calendarExportService != null) { var deleteResult = (await _calendarExportService.DeleteEventsAsync(new[] { dbEvent.LmsCalendarEventId }, param, _license)) .Single(); if (!string.IsNullOrWhiteSpace(deleteResult) && !dbEvent.LmsCalendarEventId.Equals(deleteResult, StringComparison.InvariantCultureIgnoreCase)) { // TODO: logging throw new InvalidOperationException("Some events could not be removed from Sakai calendar."); } } await RemoveCalendarEvent(dbEvent); if (meetingId != 0) { meeting.MeetingSessions.Remove(dbEvent); _lmsCourseMeetingModel.RegisterSave(meeting, true); } }
public async Task DeleteMeetingSessionsAsync(LmsCourseMeeting meeting, LtiParamDTO param) { //if (meeting.MeetingSessions.Any()) //{ // var events = new HashSet<string>(meeting.MeetingSessions.Select(x => x.EventId)); // if (_calendarExportService != null) // { //todo:uncomment if need to delete sessions from API when deleting meeting //var deleteResultIds = await _calendarExportService.DeleteEventsAsync(null, param, _license); // if (!events.SetEquals(deleteResultIds)) // { // _logger.Error( // $"List of all calendar events {string.Join(",", events)}, response is {string.Join(",", deleteResultIds.ToArray())} "); // throw new InvalidOperationException("Some events could not be removed from Sakai calendar."); // } //} // meeting.MeetingSessions.Clear(); // _lmsCourseMeetingModel.RegisterSave(meeting); //} }
public async Task DeleteMeetingSessionsAsync(LmsCourseMeeting meeting, LtiParamDTO param) { if (meeting.MeetingSessions.Any()) { var events = new HashSet <string>(meeting.MeetingSessions.Select(x => x.LmsCalendarEventId)); if (_calendarExportService != null) { var deleteResultIds = await _calendarExportService.DeleteEventsAsync(events, param, _license); if (!events.SetEquals(deleteResultIds)) { _logger.Error( $"List of all calendar events {string.Join(",", events)}, response is {string.Join(",", deleteResultIds.ToArray())} "); throw new InvalidOperationException("Some events could not be removed from Sakai calendar."); } } await RemoveCalendarEvents(meeting); meeting.MeetingSessions.Clear(); _lmsCourseMeetingModel.RegisterSave(meeting); } }
private SeminarDto GetDtoByScoInfo( IAdobeConnectProxy provider, LmsUser lmsUser, LtiParamDTO param, LmsCompany lmsCompany, ScoContent seminar, LmsCourseMeeting seminarMeeting, //TimeZoneInfo timeZone, bool isEditable, StringBuilder trace = null) { var psw = Stopwatch.StartNew(); bool meetingExistsInAC; IEnumerable <MeetingPermissionInfo> permission = provider.GetMeetingPermissions(seminar.ScoId, new List <string> { "public-access", lmsUser.PrincipalId }, out meetingExistsInAC).Values; psw.Stop(); if (trace != null) { trace.AppendFormat("\t GetMeetings - AC GetMeetingPermissions time: {0}. MeetingId: {1}\r\n", psw.Elapsed.ToString(), seminar.ScoId); } if (!meetingExistsInAC) { return(null); } var canJoin = this.CanJoin(lmsUser, permission) || GetGuestAuditRoleMappings(lmsCompany, param).Any() || (lmsCompany.UseSynchronizedUsers && seminarMeeting.EnableDynamicProvisioning); MeetingPermissionInfo permissionInfo = permission != null ? permission.FirstOrDefault(x => x.PrincipalId == "public-access" && x.PermissionId != MeetingPermissionId.none) : null; var sw = Stopwatch.StartNew(); sw.Stop(); if (trace != null) { trace.AppendFormat("\t GetMeetings - DB GetByCompanyAndScoId time: {0}. MeetingId: {1}\r\n", sw.Elapsed.ToString(), seminar.ScoId); } var scoInfo = provider.GetScoInfo(seminar.ScoId); var ret = new SeminarDto { Id = long.Parse(seminar.ScoId), AcRoomUrl = seminar.UrlPath.Trim("/".ToCharArray()), Name = seminar.Name, Summary = seminar.Description, Template = seminar.SourceScoId, StartTimeStamp = (long)seminar.BeginDate.ConvertToUnixTimestamp(), // + (long)GetTimezoneShift(timeZone, seminar.BeginDate), Duration = (seminar.EndDate - seminar.BeginDate).ToString(@"h\:mm"), // TRICK: .Replace("-", "_") for "view_hidded" on client-side AccessLevel = permissionInfo != null?permissionInfo.PermissionId.ToString().Replace("-", "_") : "remove", CanJoin = canJoin, IsEditable = isEditable, Type = (int)LmsMeetingType.Seminar, OfficeHours = null, Reused = false, AudioProfileId = scoInfo.ScoInfo.TelephonyProfile, // TODO: ???seminar.AudioProfileId SeminarLicenseId = seminar.FolderId.ToString(), }; return(ret); }
private IEnumerable <LmsCompanyRoleMapping> GetGuestAuditRoleMappings(LmsCompany lmsCompany, LtiParamDTO param) { if (!lmsCompany.GetSetting <bool>(LmsLicenseSettingNames.EnableAuditGuestEntry)) { return(Enumerable.Empty <LmsCompanyRoleMapping>()); } var customRoles = lmsCompany.RoleMappings.Where(x => !x.IsDefaultLmsRole && new[] { AcRole.Host.Id, AcRole.Presenter.Id }.Contains(x.AcRole)); var currentUserLtiRoles = new List <string>(); if (!string.IsNullOrEmpty(param.roles)) { currentUserLtiRoles.AddRange(param.roles.Split(',', ';').Select(x => x.Trim())); } return(customRoles.Where(x => currentUserLtiRoles.Any(lr => lr.Equals(x.LmsRoleName)))); }
public IEnumerable <SeminarLicenseDto> GetLicensesWithContent(IAdobeConnectProxy acProxy, IEnumerable <LmsCourseMeeting> seminarRecords, LmsUser lmsUser, LtiParamDTO param, LmsCompany lmsCompany //,TimeZoneInfo timeZone ) { if (acProxy == null) { throw new ArgumentNullException(nameof(acProxy)); } if (seminarRecords == null) { throw new ArgumentNullException(nameof(seminarRecords)); } if (lmsUser == null) { throw new ArgumentNullException(nameof(lmsUser)); } if (param == null) { throw new ArgumentNullException(nameof(param)); } if (lmsCompany == null) { throw new ArgumentNullException(nameof(lmsCompany)); } //if (timeZone == null) // throw new ArgumentNullException(nameof(timeZone)); var licenseDtos = new List <SeminarLicenseDto>(); bool canAddSeminars = UsersSetup.IsTeacher(param, lmsCompany); var sharedLicenses = GetSharedSeminarLicenses(acProxy).Where(x => !x.IsExpired); foreach (var license in sharedLicenses) { PopulateLicenseRooms( license.ScoId, license.Name, canAddSeminars, ref licenseDtos, acProxy, seminarRecords, lmsUser, param, lmsCompany //,timeZone ); } try { var userLicenses = GetUserSeminarLicenses(acProxy);//.Where(x => x.PrincipalId == lmsUser.PrincipalId); foreach (var license in userLicenses) { PopulateLicenseRooms( license.ScoId, license.Name, canAddSeminars && license.PrincipalId == lmsUser.PrincipalId, ref licenseDtos, acProxy, seminarRecords, lmsUser, param, lmsCompany //,timeZone ); } } catch (Exception ex) { _logger.Error("[GetUserSeminarLicenses] error", ex); } return(licenseDtos); }
public override async Task <(List <LmsUserDTO> users, string error)> GetUsersOldStyle(ILmsLicense lmsCompany, int courseId, LtiParamDTO param = null) { if (lmsCompany == null) { throw new ArgumentNullException(nameof(lmsCompany)); } List <LmsUserDTO> users = await FetchUsers(lmsCompany, courseId); return(GroupUsers(users), null); }
public override async Task <(LmsUserDTO user, string error)> GetUser(ILmsLicense lmsCompany, string lmsUserId, int courseId, LtiParamDTO extraData = null) { if (lmsCompany == null) { throw new ArgumentNullException(nameof(lmsCompany)); } if (lmsCompany.AdminUser == null) { Logger.ErrorFormat("There is no admin user set for LmsCompanyId={0}.", lmsCompany.Id); throw new WarningMessageException(Resources.Messages.NoLicenseAdmin); } var token = lmsCompany.AdminUser.Token; if (string.IsNullOrWhiteSpace(token)) { Logger.ErrorFormat("There is no admin user set for LmsCompanyId={0}. (AdminUser has EMPTY token).", lmsCompany.Id); throw new WarningMessageException(Resources.Messages.NoLicenseAdmin); } var user = await _canvasApi.GetCourseUser( lmsUserId, lmsCompany, token, courseId); return(user, null); }
public async Task <IEnumerable <string> > DeleteEventsAsync(IEnumerable <string> eventIds, LtiParamDTO param, ILmsLicense license) { List <string> ids = new List <string>(); foreach (var id in eventIds) { var result = await _api.DeleteSession(param.course_id.ToString(), id, license.GetLMSSettings(_settings)); if (result) { ids.Add(id); } } return(ids); //var events = eventIds.Select(x => new SakaiEventDelete() //{ // SakaiId = x //}); //var apiParam = new SakaiApiDeleteObject //{ // Params = new SakaiParams { LtiMessageType = "egc-delete-calendars" }, // Calendars = new SakaiCalendarDelete[] // { // new SakaiCalendarDelete() // { // SiteId = param.context_id, // CalendarReference = "main", // Events = events.ToArray() // } // } //}; //var json = JsonConvert.SerializeObject(apiParam); //string resp = await _httpClientWrapper.UploadJsonStringAsync(GetApiUrl(param), json); //return resp.Replace("\n", String.Empty).Replace("\r", String.Empty).Split(','); }
public async Task <IEnumerable <MeetingSessionDTO> > SaveEventsAsync(int meetingId, IEnumerable <MeetingSessionDTO> eventDtos, LtiParamDTO param, ILmsLicense license) { List <MeetingSessionDTO> result = eventDtos.ToList(); IEnumerable <LiveSessionResponse> sessions = await _api.CreateSessions(param.course_id.ToString(), eventDtos.Select(x => new LiveSessionRequest { start_at = x.StartDate, end_at = x.EndDate, notes = x.Summary }), license.GetLMSSettings(_settings)); var users = await _api.GetCourseUsers(param.course_id.ToString(), license.GetLMSSettings(_settings)); foreach (var session in sessions) { var webConf = await _api.UpdateSessionWebconference(param.course_id.ToString(), session.id, new WebConferenceRequest { provider = "Other", other_provider = "eSyncTraining AC", meeting_url = $"{_settings.BasePath.TrimEnd('/')}/lti/meeting/join?session={"123"}&meetingId={meetingId}" }, license.GetLMSSettings(_settings)); var publishedSession = await _api.PublishSession(param.course_id.ToString(), session.id, license.GetLMSSettings(_settings)); foreach (var user in users) { var userRegistered = await _api.RegisterUserToSession(session.id, user.Id, license.GetLMSSettings(_settings)); } //var evt = result.FirstOrDefault(x => session.start_at.Value == x.StartDate); //if (evt != null) //{ // evt.EventId = session.id.ToString(); //} } //return result; return(sessions.Select(ConvertToDto)); }
public async Task <IEnumerable <MeetingSessionDTO> > SaveEventsAsync(int meetingId, IEnumerable <MeetingSessionDTO> eventDtos, LtiParamDTO param, ILmsLicense license) { var apiParam = new SakaiApiObject { Params = new SakaiParams { LtiMessageType = "egc-submit-calendars" }, Calendars = new SakaiCalendar[] { new SakaiCalendar { MeetingId = meetingId.ToString(), SiteId = param.context_id, CalendarReference = "main", ButtonSource = "https://www.incommon.org/images/joinbutton_03.png", Secret = param.oauth_consumer_key, Events = eventDtos.Select(ConvertSessionDtoToApiDto).ToArray() } } }; var json = JsonConvert.SerializeObject(apiParam); var client = _httpClientFactory.CreateClient(); var content = new StringContent(json, Encoding.UTF8, "application/json"); var response = await client.PostAsync(GetApiUrl(param), content); var resp = await response.Content.ReadAsStringAsync(); var events = JsonConvert.DeserializeObject <ExternalEventDto[]>(resp); var sessions = events.Select(ConvertFromApiDtoToSessionDto).ToList(); foreach (var session in sessions) { var inEvent = eventDtos.SingleOrDefault(x => x.EventId == session.EventId); if (inEvent != null) { session.Id = inEvent.Id; } } return(sessions); }
public async Task <IEnumerable <MeetingSessionDTO> > CreateBatchAsync(CreateMeetingSessionsBatchDto dto, LtiParamDTO param) { LmsCourseMeeting meeting = _lmsCourseMeetingModel.GetOneById(dto.MeetingId).Value; DateTime startDate = dto.StartTimestamp; if (dto.StartTimestamp < DateTime.UtcNow) //todo: remove these crazy conditions and parsing { throw new ArgumentException("Start time should be more then current time"); } var endDate = TimeSpan.TryParse(dto.Duration, out var duration) ? startDate.AddMinutes((int)duration.TotalMinutes) : startDate.AddHours(1); MeetingNameInfo nameInfo = string.IsNullOrWhiteSpace(meeting.MeetingNameJson) ? new MeetingNameInfo() : JsonConvert.DeserializeObject <MeetingNameInfo>(meeting.MeetingNameJson); var meetingName = nameInfo.meetingName ?? nameInfo.reusedMeetingName; int i = 1; var latestDateToCheck = startDate.AddDays(dto.Weeks * 7); var listOfEvents = new List <MeetingSessionDTO>(); while (startDate < latestDateToCheck) { if (dto.DaysOfWeek.Contains((int)startDate.DayOfWeek)) { var ev = new MeetingSessionDTO { Name = meetingName + " #" + i.ToString(), Summary = string.Empty, StartDate = startDate, //.ToString("yyyy-MM-dd HH:mm"), EndDate = endDate, //.ToString("yyyy-MM-dd HH:mm"), }; listOfEvents.Add(ev); i++; } startDate = startDate.AddDays(1); endDate = endDate.AddDays(1); } if (_calendarExportService != null) { listOfEvents = (await _calendarExportService.SaveEventsAsync(meeting.Id, listOfEvents, param, _license)) .ToList(); } meeting.MeetingSessions.AddRange(listOfEvents.Select(x => new LmsMeetingSession { LmsCalendarEventId = x.EventId, Name = x.Name, StartDate = x.StartDate, EndDate = x.EndDate, LmsCourseMeeting = meeting })); await CreateCalendarEvents(param, meeting); _lmsCourseMeetingModel.RegisterSave(meeting, true); return(meeting.MeetingSessions.Select(ConvertFromEntity).ToArray()); }
public async Task <IEnumerable <string> > DeleteEventsAsync(IEnumerable <string> eventIds, LtiParamDTO param, ILmsLicense license) { var events = eventIds.Select(x => new SakaiEventDelete() { SakaiId = x }); var apiParam = new SakaiApiDeleteObject { Params = new SakaiParams { LtiMessageType = "egc-delete-calendars" }, Calendars = new SakaiCalendarDelete[] { new SakaiCalendarDelete() { SiteId = param.context_id, CalendarReference = "main", Events = events.ToArray() } } }; var json = JsonConvert.SerializeObject(apiParam); var client = _httpClientFactory.CreateClient(); var content = new StringContent(json, Encoding.UTF8, "application/json"); var response = await client.PostAsync(GetApiUrl(param), content); var resp = await response.Content.ReadAsStringAsync(); return(resp.Replace("\n", String.Empty).Replace("\r", String.Empty).Split(',')); }
public override async Task <OperationResultWithData <List <LmsUserDTO> > > GetUsers(ILmsLicense lmsCompany, int courseId, LtiParamDTO extraData = null) { if (lmsCompany == null) { throw new ArgumentNullException(nameof(lmsCompany)); } if (lmsCompany.AdminUser == null) { var message = string.Format("There is no admin user set for LmsCompanyId={0}.CourseId={1}", lmsCompany.Id, courseId); Logger.Error(message); return(OperationResultWithData <List <LmsUserDTO> > .Error(Resources.Messages.NoLicenseAdmin)); } if (string.IsNullOrWhiteSpace(lmsCompany.AdminUser.Token)) { Logger.ErrorFormat("There is no admin user set for LmsCompanyId={0}. (AdminUser has EMPTY token).", lmsCompany.Id); return(OperationResultWithData <List <LmsUserDTO> > .Error(Resources.Messages.NoLicenseAdmin)); } List <LmsUserDTO> users = await FetchUsers(lmsCompany, courseId); return(users.ToSuccessResult()); }
public async Task <MeetingSessionDTO> SaveSessionAsync(int meetingId, MeetingSessionDTO dto, LtiParamDTO param) { LmsCourseMeeting meeting = _lmsCourseMeetingModel.GetOneById(meetingId).Value; var meetingSession = GetMeetingSession(dto, meeting); if (meetingSession.Id == 0) { meeting.MeetingSessions.Add(meetingSession); } await UpdateCalendarEvent(dto, param, meetingSession); UpdateMeetingSession(dto, meetingSession); _lmsCourseMeetingModel.RegisterSave(meeting, true); return(ConvertFromEntity(meetingSession)); }