Exemple #1
0
        public async Task <OperationResultWithData <SlotDto> > DenySlotByDate(int ohId, DateTime start, LmsUser lmsUser)
        {
            var dbSlot = _slotModel.GetSlotForDate(start, ohId);

            if (dbSlot != null)
            {
                dbSlot.Status = (int)OfficeHoursSlotStatus.Cancelled;
                _slotModel.RegisterSave(dbSlot, true);
                return(ConvertToDto(dbSlot, lmsUser.Id).ToSuccessResult());
            }

            var slots = await GetSlots(ohId, lmsUser.Id, start, start.AddMinutes(30)); // 30 - max time of slots

            var slot = slots.FirstOrDefault(x => x.Start == start);

            if (slot == null)
            {
                return(OperationResultWithData <SlotDto> .Error(
                           "Time of selected slot is out of any availability range."));
            }

            //slot.Subject = "";
            var resultDto = await AddSlots(ohId, lmsUser, new[] { slot }, OfficeHoursSlotStatus.Cancelled);

            return(resultDto.IsSuccess ? resultDto.Data.First().ToSuccessResult() : OperationResultWithData <SlotDto> .Error(resultDto.Message));
        }
Exemple #2
0
        public virtual OperationResultWithData <IEnumerable <MeetingItemDto> > SearchExistingMeeting(
            [FromBody] SearchRequestDto request)
        {
            try
            {
                if (Session.LmsUser == null)
                {
                    return(OperationResultWithData <IEnumerable <MeetingItemDto> > .Error(
                               "Session doesn't contain LMS user."));
                }
                if (string.IsNullOrWhiteSpace(Session.LmsUser.PrincipalId))
                {
                    return(OperationResultWithData <IEnumerable <MeetingItemDto> > .Error(
                               "You don't have Adobe Connect account."));
                }

                var provider     = GetAdminProvider();
                var principal    = provider.GetOneByPrincipalId(Session.LmsUser.PrincipalId).PrincipalInfo.Principal;
                var userProvider = GetUserProvider();

                var myMeetings = userProvider.ReportMyMeetings(MeetingPermissionId.host).Values
                                 .Where(x => x.Name.IndexOf(request.SearchTerm, StringComparison.OrdinalIgnoreCase) >= 0 ||
                                        x.UrlPath.IndexOf(request.SearchTerm, StringComparison.OrdinalIgnoreCase) >= 0);

                return(myMeetings.Select(MeetingItemDto.Build).ToSuccessResult());
            }
            catch (Exception ex)
            {
                string errorMessage = GetOutputErrorMessage("AcMeetingController.SearchExistingMeeting", ex);
                return(OperationResultWithData <IEnumerable <MeetingItemDto> > .Error(errorMessage));
            }
        }
Exemple #3
0
        public virtual OperationResultWithData <string> AccessMp4File(string scoId)
        {
            try
            {
                var       ac = this.GetAdminProvider();
                string    breezeToken;
                Principal principal = GetPrincipal(this.LmsCompany, Session.LtiSession.LtiParam, scoId, ac, out breezeToken);

                OperationResultWithData <string> result = new SubtitleUtility(ac, Logger).AccessMp4File(scoId,
                                                                                                        LmsCompany.AcServer,
                                                                                                        principal.PrincipalId,
                                                                                                        breezeToken);

                if (result.IsSuccess)
                {
                    return(result);
                }

                return(OperationResultWithData <string> .Error(IsDebug
                                                               ?result.Message
                                                               : "An exception is occured. Try again later or contact your administrator."));
            }
            catch (WarningMessageException ex)
            {
                return(OperationResultWithData <string> .Error(ex.Message));
            }
            catch (Exception ex)
            {
                Logger.ErrorFormat(ex, "Mp4Video exception. sco-id:{0}. SessionID: {1}.", scoId, Session.Id);

                return(OperationResultWithData <string> .Error(IsDebug
                                                               ?(ex.Message + ex.StackTrace)
                                                               : "An exception is occured. Try again later or contact your administrator."));
            }
        }
Exemple #4
0
        public OperationResultWithData <FolderDto> CreateSubFolder(string folderScoId, [FromBody] FolderDto dto)
        {
            if (dto == null)
            {
                throw new ArgumentNullException(nameof(dto));
            }

            try
            {
                if (!LmsCompany.GetSetting <bool>(LmsCompanySettingNames.EnableMyContent))
                {
                    return(OperationResultWithData <FolderDto> .Error("Operation is not enabled."));
                }

                // TRICK:
                dto.FolderId = folderScoId;

                var ac     = this.GetUserProvider();
                var helper = new ContentEditControllerHelper(Logger, ac);
                return(helper.CreateFolder(dto));
            }
            catch (Exception ex)
            {
                string errorMessage = GetOutputErrorMessage("ContentApi-CreateSubFolder", ex);
                return(OperationResultWithData <FolderDto> .Error(errorMessage));
            }
        }
Exemple #5
0
        public virtual async Task <OperationResultWithData <Mp4TaskStatusDto> > GetRecordingStatus([FromBody] RecordingActionRequestDto input)
        {
            try
            {
                Guid mp4;
                if (!Guid.TryParse(LmsCompany.GetSetting <string>(LmsLicenseSettingNames.Mp4ServiceLicenseKey), out mp4))
                {
                    mp4 = Guid.Empty;
                }
                Guid mp4Subtitles;
                if (!Guid.TryParse(LmsCompany.GetSetting <string>(LmsLicenseSettingNames.Mp4ServiceWithSubtitlesLicenseKey), out mp4Subtitles))
                {
                    mp4Subtitles = Guid.Empty;
                }

                if ((mp4 != Guid.Empty) || (mp4Subtitles != Guid.Empty))
                {
                    var mp4Client = IoC.Resolve <TaskClient>();
                    return(await Mp4ApiUtility.GetRecordingStatus(mp4Client, input.RecordingId,
                                                                  mp4,
                                                                  mp4Subtitles,
                                                                  _mp4LinkBuilder,
                                                                  _vttLinkBuilder,
                                                                  Logger));
                }

                return(OperationResultWithData <Mp4TaskStatusDto> .Error("No MP4 license found"));
            }
            catch (Exception ex)
            {
                string errorMessage = GetOutputErrorMessage("MP4-GetRecordings", ex);
                return(OperationResultWithData <Mp4TaskStatusDto> .Error(errorMessage));
            }
        }
Exemple #6
0
        //public async Task<OperationResultWithData<IEnumerable<TDto>>> GetShortcuts(IEnumerable<ScoShortcutType> typesToReturn)
        //{
        //    try
        //    {
        //        return OperationResultWithData<IEnumerable<TDto>>.Success(_contentService.GetShortcuts(typesToReturn).Select(x => _mapper.Map(x)));
        //    }
        //    catch (AdobeConnectException ex)
        //    {
        //        string errorMessage = GetOutputErrorMessage("GetShortcuts", ex);
        //        return OperationResultWithData<IEnumerable<TDto>>.Error(errorMessage);
        //    }
        //    catch (Exception ex)
        //    {
        //        string errorMessage = GetOutputErrorMessage("GetShortcuts", ex);
        //        return OperationResultWithData<IEnumerable<TDto>>.Error(errorMessage);
        //    }
        //}

        //[HttpGet]
        //[Route("my-content")]
        //public async Task<OperationResultWithData<IEnumerable<TDto>>> GetMyContent()
        //{
        //    try
        //    {
        //        return OperationResultWithData<IEnumerable<TDto>>.Success(_contentService.GetMyContent().Select(x => _mapper.Map(x)));
        //    }
        //    catch (AdobeConnectException ex)
        //    {
        //        if (ex.Status.Code == StatusCodes.no_access && ex.Status.SubCode == StatusSubCodes.denied)
        //        {
        //            return OperationResultWithData<IEnumerable<TDto>>.Error("You do not have permission to access this item.");
        //        }

        //        string errorMessage = GetOutputErrorMessage("GetMyContent", ex);
        //        return OperationResultWithData<IEnumerable<TDto>>.Error(errorMessage);
        //    }
        //    catch (Exception ex)
        //    {
        //        string errorMessage = GetOutputErrorMessage("GetMyContent", ex);
        //        return OperationResultWithData<IEnumerable<TDto>>.Error(errorMessage);
        //    }
        //}

        //public async Task<OperationResultWithData<IEnumerable<TDto>>> GetUserContent(string userLogin)
        //{
        //    if (string.IsNullOrWhiteSpace(userLogin))
        //        throw new ArgumentException("Non-empty value expected", nameof(userLogin));

        //    try
        //    {
        //        return OperationResultWithData<IEnumerable<TDto>>.Success(_contentService.GetUserContent(userLogin).Select(x => _mapper.Map(x)));
        //    }
        //    catch (AdobeConnectException ex)
        //    {
        //        if (ex.Status.Code == StatusCodes.no_access && ex.Status.SubCode == StatusSubCodes.denied)
        //        {
        //            return OperationResultWithData<IEnumerable<TDto>>.Error("You do not have permission to access this item.");
        //        }

        //        string errorMessage = GetOutputErrorMessage("GetMyContent", ex);
        //        return OperationResultWithData<IEnumerable<TDto>>.Error(errorMessage);
        //    }
        //    catch (Exception ex)
        //    {
        //        string errorMessage = GetOutputErrorMessage("GetMyContent", ex);
        //        return OperationResultWithData<IEnumerable<TDto>>.Error(errorMessage);
        //    }
        //}

        //public async Task<OperationResultWithData<IEnumerable<TDto>>> GetSharedContent()
        //{
        //    try
        //    {
        //        return OperationResultWithData<IEnumerable<TDto>>.Success(_contentService.GetSharedContent().Select(x => _mapper.Map(x)));
        //    }
        //    catch (AdobeConnectException ex)
        //    {
        //        if (ex.Status.Code == StatusCodes.no_access && ex.Status.SubCode == StatusSubCodes.denied)
        //        {
        //            return OperationResultWithData<IEnumerable<TDto>>.Error("You do not have permission to access this item.");
        //        }

        //        string errorMessage = GetOutputErrorMessage("GetSharedContent", ex);
        //        return OperationResultWithData<IEnumerable<TDto>>.Error(errorMessage);
        //    }
        //    catch (Exception ex)
        //    {
        //        string errorMessage = GetOutputErrorMessage("GetSharedContent", ex);
        //        return OperationResultWithData<IEnumerable<TDto>>.Error(errorMessage);
        //    }
        //}

        public async Task <OperationResultWithData <IEnumerable <TDto> > > GetFolderContent(string folderScoId, IDtoProcessor <TDto> processor)
        {
            if (string.IsNullOrWhiteSpace(folderScoId))
            {
                throw new ArgumentException("Non-empty value expected", nameof(folderScoId));
            }
            if (processor == null)
            {
                throw new ArgumentNullException(nameof(processor));
            }

            try
            {
                var result = _contentService.GetFolderContent(folderScoId)
                             .Select(x => _mapper.Map(x))
                             .Select(y => processor.Process(y));

                return(OperationResultWithData <IEnumerable <TDto> > .Success(result));
            }
            catch (AdobeConnectException ex)
            {
                if (ex.Status.Code == StatusCodes.no_access && ex.Status.SubCode == StatusSubCodes.denied)
                {
                    return(OperationResultWithData <IEnumerable <TDto> > .Error("You do not have permission to access this item."));
                }

                string errorMessage = GetOutputErrorMessage("FolderContent", ex);
                return(OperationResultWithData <IEnumerable <TDto> > .Error(errorMessage));
            }
            catch (Exception ex)
            {
                string errorMessage = GetOutputErrorMessage("FolderContent", ex);
                return(OperationResultWithData <IEnumerable <TDto> > .Error(errorMessage));
            }
        }
Exemple #7
0
        public virtual OperationResultWithData <bool> CheckPasswordBeforeJoin()
        {
            try
            {
                bool isValid = false;
                var  param   = Session.LtiSession.With(x => x.LtiParam);
                var  lmsUser = this.lmsUserModel.GetOneByUserIdAndCompanyLms(param.lms_user_id, LmsCompany.Id).Value;
                if (lmsUser != null)
                {
                    var mode = lmsUser.AcConnectionMode;
                    switch (mode)
                    {
                    case AcConnectionMode.DontOverwriteLocalPassword:
                        isValid = !string.IsNullOrWhiteSpace(lmsUser.ACPassword);
                        break;

                    default:
                        isValid = true;
                        break;
                    }
                }

                return(isValid.ToSuccessResult());
            }
            catch (Exception ex)
            {
                string errorMessage = GetOutputErrorMessage("CheckPasswordBeforeJoin", ex);
                return(OperationResultWithData <bool> .Error(errorMessage));
            }
        }
Exemple #8
0
        public virtual OperationResultWithData <IEnumerable <ACSessionDto> > GetSessionsReport([FromBody] ReportRequestDto request)
        {
            try
            {
                LmsCourseMeeting meeting = LmsCourseMeetingModel.GetOneByCourseAndId(LmsCompany.Id, CourseId, request.MeetingId);
                if (meeting == null)
                {
                    return(OperationResultWithData <IEnumerable <ACSessionDto> > .Error(Messages.MeetingNotFound));
                }

                IEnumerable <ACSessionDto> report = _reportService.GetSessionsReports(
                    meeting.GetMeetingScoId(),
                    GetAdminProvider(),
                    TimeZoneInfo.Utc,
                    request.StartIndex,
                    request.Limit);

                return(report.ToSuccessResult());
            }
            catch (Exception ex)
            {
                string errorMessage = GetOutputErrorMessage("GetSessionsReport", ex);
                return(OperationResultWithData <IEnumerable <ACSessionDto> > .Error(errorMessage));
            }
        }
Exemple #9
0
        public OperationResultWithData <IEnumerable <ScoShortcutDto> > GetShortcuts()
        {
            try
            {
                if (!LmsCompany.GetSetting <bool>(LmsCompanySettingNames.EnableMyContent))
                {
                    return(OperationResultWithData <IEnumerable <ScoShortcutDto> > .Error("Operation is not enabled."));
                }

                var param = Session.LtiSession.LtiParam;
                var ac    = this.GetUserProvider();

                var lmsUser = _lmsUserModel.GetOneByUserIdAndCompanyLms(param.lms_user_id, LmsCompany.Id).Value;

                var contentService = new ContentService(Logger, ac);
                IEnumerable <ScoShortcut> shortcuts = contentService.GetShortcuts(new ScoShortcutType[] { ScoShortcutType.content, ScoShortcutType.my_content });

                var result = shortcuts.Select(x => new ScoShortcutDto
                {
                    ScoId = x.ScoId,
                    Type  = x.Type,
                    Name  = Resources.ScoShortcutNames.ResourceManager.GetString(x.Type.Replace('-', '_')), // TRICK: AC trick to change my-content to my_content
                });

                return(result.ToSuccessResult());
            }
            catch (Exception ex)
            {
                string errorMessage = GetOutputErrorMessage("ContentApi-GetShortcuts", ex);
                return(OperationResultWithData <IEnumerable <ScoShortcutDto> > .Error(errorMessage));
            }
        }
Exemple #10
0
        public override async Task <OperationResultWithData <LmsUserDTO> > GetUser(Dictionary <string, object> licenseSettings, string lmsUserId, string courseId, ILtiUserListParam extraData = null)
        {
            if (licenseSettings == null)
            {
                throw new ArgumentNullException(nameof(licenseSettings));
            }

            var param = extraData;
            //todo: to license/session settings
            var isCurrentUserAndAdmin =
                param != null &&
                param.lms_user_id == lmsUserId &&
                ((param.roles != null && param.roles.Contains("Administrator")) ||
                 (param.ext_d2l_role != null && param.ext_d2l_role.ToLower().Contains("administrator")));

            //if current user is admin but not allowed to call api - process 'error' parameter in call stack
            if (isCurrentUserAndAdmin)
            {
                var error = $"[GetD2LUsers] AdminUser is not set for LmsCompany with key={licenseSettings[LmsLicenseSettingNames.LicenseKey]}";
                return(OperationResultWithData <LmsUserDTO> .Error(error));
            }

            var result = await GetUsers(licenseSettings, courseId, extraData);

            return(result.IsSuccess
                ? result.Data.FirstOrDefault(u => u.Id == lmsUserId)?.ToSuccessResult()
                : OperationResultWithData <LmsUserDTO> .Error(result.Message));
        }
Exemple #11
0
        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());
        }
Exemple #12
0
        //public async Task<OperationResultWithData<IEnumerable<TDto>>> GetMyMeetings()
        //{
        //    try
        //    {
        //        return OperationResultWithData<IEnumerable<TDto>>.Success(_meetingService.GetUserMeetings().Select(x => _mapper.Map(x)));
        //    }
        //    catch (AdobeConnectException ex)
        //    {
        //        if (ex.Status.Code == StatusCodes.no_access && ex.Status.SubCode == StatusSubCodes.denied)
        //        {
        //            return OperationResultWithData<IEnumerable<TDto>>.Error("You do not have permission to access this item.");
        //        }

        //        string errorMessage = GetOutputErrorMessage("GetMyMeetings", ex);
        //        return OperationResultWithData<IEnumerable<TDto>>.Error(errorMessage);
        //    }
        //    catch (Exception ex)
        //    {
        //        string errorMessage = GetOutputErrorMessage("GetMyMeetings", ex);
        //        return OperationResultWithData<IEnumerable<TDto>>.Error(errorMessage);
        //    }
        //}

        //public async Task<OperationResultWithData<IEnumerable<TDto>>> GetSharedMeetings()
        //{
        //    try
        //    {
        //        return OperationResultWithData<IEnumerable<TDto>>.Success(_meetingService.GetSharedMeetings().Select(x => _mapper.Map(x)));
        //    }
        //    catch (AdobeConnectException ex)
        //    {
        //        if (ex.Status.Code == StatusCodes.no_access && ex.Status.SubCode == StatusSubCodes.denied)
        //        {
        //            return OperationResultWithData<IEnumerable<TDto>>.Error("You do not have permission to access this item.");
        //        }

        //        string errorMessage = GetOutputErrorMessage("GetSharedMeetings", ex);
        //        return OperationResultWithData<IEnumerable<TDto>>.Error(errorMessage);
        //    }
        //    catch (Exception ex)
        //    {
        //        string errorMessage = GetOutputErrorMessage("GetSharedMeetings", ex);
        //        return OperationResultWithData<IEnumerable<TDto>>.Error(errorMessage);
        //    }
        //}

        public async Task <OperationResultWithData <IEnumerable <TDto> > > FolderContent(string folderScoId)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(folderScoId))
                {
                    throw new ArgumentException("folderScoId can't be empty", nameof(folderScoId));
                }

                return(_meetingService.GetFolderMeetings(folderScoId).Select(x => _mapper.Map(x)).ToSuccessResult());
            }
            catch (AdobeConnectException ex)
            {
                if (ex.Status.Code == StatusCodes.no_access && ex.Status.SubCode == StatusSubCodes.denied)
                {
                    return(OperationResultWithData <IEnumerable <TDto> > .Error("You do not have permission to access this item."));
                }

                string errorMessage = GetOutputErrorMessage("FolderContent", ex);
                return(OperationResultWithData <IEnumerable <TDto> > .Error(errorMessage));
            }
            catch (Exception ex)
            {
                string errorMessage = GetOutputErrorMessage("FolderContent", ex);
                return(OperationResultWithData <IEnumerable <TDto> > .Error(errorMessage));
            }
        }
Exemple #13
0
        public OperationResultWithData <string> GetDownloadAsZipLink(string scoId, string breezeToken)
        {
            if (string.IsNullOrWhiteSpace(scoId))
            {
                throw new ArgumentException("Non-empty value expected", nameof(scoId));
            }
            if (string.IsNullOrWhiteSpace(breezeToken))
            {
                throw new ArgumentException("Non-empty value expected", nameof(breezeToken));
            }

            try
            {
                string url = _contentService.GetDownloadAsZipLink(scoId, breezeToken);

                return(OperationResultWithData <string> .Success(url));
            }
            catch (WarningMessageException ex)
            {
                return(OperationResultWithData <string> .Error(ex.Message));
            }
            catch (Exception ex)
            {
                _logger.ErrorFormat(ex, "AccessFile exception. sco-id:{0}.", scoId);
                return(OperationResultWithData <string> .Error(ex.Message + ex.StackTrace));
            }
        }
Exemple #14
0
        public OperationResult GetDownloadLink(string scoId)
        {
            try
            {
                var ac             = this.GetUserProvider();
                var contentService = new ContentService(Logger, ac);
                var helper         = new ContentControllerHelper <ScoContentDto>(Logger, contentService, new ScoContentDtoMapper());

                var param   = Session.LtiSession.LtiParam;
                var lmsUser = _lmsUserModel.GetOneByUserIdAndCompanyLms(param.lms_user_id, LmsCompany.Id).Value;
                if (lmsUser == null)
                {
                    throw new EdugameCloud.Lti.Core.WarningMessageException($"No user with id {param.lms_user_id} found in the database.");
                }

                string breezeToken = MeetingSetup.ACLogin(LmsCompany, param, lmsUser, ac).BreezeSession;

                return(helper.GetDownloadAsZipLink(scoId, breezeToken));
            }
            catch (Exception ex)
            {
                string errorMessage = GetOutputErrorMessage("ContentApi-GetDownloadLink", ex);
                return(OperationResultWithData <IEnumerable <ScoContentDto> > .Error(errorMessage));
            }
        }
Exemple #15
0
        public async Task <OperationResultWithData <SlotDto> > BookSlot([FromBody] CreateSlotDto dto)
        {
            LmsCourseMeeting meeting = _lmsCourseMeetingModel.GetOneByCourseAndId(LmsCompany.Id, CourseId, dto.MeetingId);

            if (meeting?.OfficeHours == null)
            {
                return(OperationResultWithData <SlotDto> .Error("Meeting not found"));
            }

            var slotResult = await _officeHoursService.AddSlots(meeting.OfficeHours.Id, Session.LmsUser, new[] { dto }, status : OfficeHoursSlotStatus.Booked);

            //if (slotResult.IsSuccess)
            //{
            //    var details = await _meetingApiService.GetMeetingApiDetails(meeting);
            //    var host = _userService.GetUser(meeting.ProviderHostId); //todo: get user data from lmsUser table
            //    if (host != null)
            //    {
            //        _queue.QueueBackgroundWorkItem(async token =>
            //        {
            //            await _notificationService.SendOHBookSlotEmail(slotResult.Data.First(), details.Topic, host.Email,
            //                $"{host.FirstName} {host.LastName}");
            //            Logger.Info($"Email for slotId={slotResult.Data.First().Id} is sent to host {host.Email}");
            //        });
            //    }
            //}

            return(slotResult.IsSuccess ? slotResult.Data.First().ToSuccessResult() : OperationResultWithData <SlotDto> .Error(slotResult.Message));
        }
Exemple #16
0
        public async Task <OperationResultWithData <IEnumerable <LmsQuizInfoDTO> > > GetItemsInfoForUserAsync(Dictionary <string, object> licenseSettings, bool isSurvey)
        {
            string error = null;

            try
            {
                var moodleServiceToken = (string)licenseSettings[LmsLicenseSettingNames.MoodleQuizServiceToken];
                //var quizResult = !string.IsNullOrEmpty(moodleServiceToken)
                //    ? GetQuizzes(moodleServiceToken, isSurvey, lmsUserParameters.Course, lmsUserParameters.CompanyLms)
                //    : LoginIfNecessary(
                //    null,
                //    c =>
                //    {
                //        return GetQuizzes(c.Token, isSurvey, lmsUserParameters.Course, lmsUserParameters.CompanyLms);
                //    },
                //    out error,
                //    lmsUserParameters.LmsUser);
                //-----------------
                IEnumerable <LmsQuizInfoDTO> quizResult;
                if (!string.IsNullOrEmpty(moodleServiceToken))
                {
                    quizResult = await GetQuizzes(moodleServiceToken, isSurvey, (string)licenseSettings[LmsUserSettingNames.CourseId], licenseSettings);
                }
                else
                {
                    var quizResultTuple = await LoginIfNecessary(
                        null,
                        async c =>
                    {
                        return(await GetQuizzes(c.Token, isSurvey, (string)licenseSettings[LmsUserSettingNames.CourseId], licenseSettings));
                    },
                        licenseSettings);

                    //popov
                    quizResult = await quizResultTuple.result;
                    error      = quizResultTuple.error;
                }
                //-----------------

                if (quizResult == null)
                {
                    error = error ?? "Moodle XML. Unable to retrive result from API";
                    Logger.ErrorFormat("[EGCEnabledMoodleApi.GetItemsInfoForUser] LmsUserParametersId:{0}. IsSurvey:{1}. Error: {2}.", licenseSettings[LmsUserSettingNames.SessionId], isSurvey, error);
                    return(OperationResultWithData <IEnumerable <LmsQuizInfoDTO> > .Error(error));
                }

                return(quizResult.ToSuccessResult());
            }
            catch (Exception ex)
            {
                Logger.ErrorFormat(ex, "[EGCEnabledMoodleApi.GetItemsInfoForUser] LmsUserParametersId:{0}. IsSurvey:{1}.", licenseSettings[LmsUserSettingNames.SessionId], isSurvey);
                throw;
            }
        }
Exemple #17
0
        public async Task <OperationResultWithData <List <SlotDto> > > RescheduleDate([FromBody] RescheduleDateDto dto)
        {
            LmsCourseMeeting meeting = _lmsCourseMeetingModel.GetOneByCourseAndId(LmsCompany.Id, CourseId, dto.MeetingId);

            if (meeting?.OfficeHours == null)
            {
                return(OperationResultWithData <List <SlotDto> > .Error("Meeting not found"));
            }
            var slots = await _officeHoursService.RescheduleDate(meeting.OfficeHours.Id, Session.LmsUser, dto);

            return(slots);
        }
Exemple #18
0
        public async Task <OperationResultWithData <OfficeHoursTeacherAvailabilityDto> > AddAvailabitily([FromBody] OfficeHoursTeacherAvailabilityDto dto)
        {
            LmsCourseMeeting meeting = _lmsCourseMeetingModel.GetOneByCourseAndId(LmsCompany.Id, CourseId, dto.MeetingId);

            if (meeting?.OfficeHours == null)
            {
                return(OperationResultWithData <OfficeHoursTeacherAvailabilityDto> .Error("Meeting not found"));
            }
            var result = await _officeHoursService.AddAvailability(meeting.OfficeHours, Session.LmsUser, dto);

            return(result);
        }
Exemple #19
0
        public async Task <OperationResultWithData <IEnumerable <OfficeHoursTeacherAvailabilityDto> > > GetAvailabilities([FromBody] MeetingIdDto dto)
        {
            LmsCourseMeeting meeting = _lmsCourseMeetingModel.GetOneByCourseAndId(LmsCompany.Id, CourseId, dto.MeetingId);

            if (meeting?.OfficeHours == null)
            {
                return(OperationResultWithData <IEnumerable <OfficeHoursTeacherAvailabilityDto> > .Error("Meeting not found"));
            }
            var availabilities = await _officeHoursService.GetAvailabilities(meeting.OfficeHours.Id, null); //todo: show slots accross the courses

            return(availabilities.ToSuccessResult());
        }
Exemple #20
0
        public async Task <OperationResult> ResetDeniedDate([FromBody] DenyDateDto dto)
        {
            LmsCourseMeeting meeting = _lmsCourseMeetingModel.GetOneByCourseAndId(LmsCompany.Id, CourseId, dto.MeetingId);

            if (meeting?.OfficeHours == null)
            {
                return(OperationResultWithData <IEnumerable <SlotDto> > .Error("Meeting not found"));
            }
            var result = await _officeHoursService.ResetDeniedSlots(meeting.OfficeHours.Id, dto);

            return(result);
        }
Exemple #21
0
        [LmsAuthorizeBase] // TeacherOnly ?
        public async Task <OperationResultWithData <SlotDto> > DenySlotByDate([FromBody] DenySlotByDateDto dto)
        {
            LmsCourseMeeting meeting = _lmsCourseMeetingModel.GetOneByCourseAndId(LmsCompany.Id, CourseId, dto.MeetingId);

            if (meeting?.OfficeHours == null)
            {
                return(OperationResultWithData <SlotDto> .Error("Meeting not found"));
            }
            var result = await _officeHoursService.DenySlotByDate(meeting.OfficeHours.Id, dto.Start, Session.LmsUser);

            return(result);
        }
Exemple #22
0
        private async Task <OperationResultWithData <SlotDto> > UpdateSlotStatusInternal(int slotId, OfficeHoursSlotStatus status, LmsUser lmsUser)
        {
            var slot = _slotModel.GetOneById(slotId).Value;

            if (slot == null)
            {
                return(OperationResultWithData <SlotDto> .Error("Slot not found"));
            }

            slot.Status = (int)status;
            _slotModel.RegisterSave(slot, true);
            return(ConvertToDto(slot, lmsUser.Id).ToSuccessResult());
        }
Exemple #23
0
 public virtual OperationResultWithData <string> GetRecordingPasscode([FromBody] RecordingPasscodeRequestDto input)
 {
     try
     {
         string passCode = RecordingsService.GetPasscode(LmsCompany, GetAdminProvider(), input.RecordingId);
         return(passCode.ToSuccessResult());
     }
     catch (Exception ex)
     {
         string errorMessage = GetOutputErrorMessage("GetRecordingPasscode", ex);
         return(OperationResultWithData <string> .Error(errorMessage));
     }
 }
Exemple #24
0
        public OperationResultWithData <FolderDto> CreateFolder(FolderDto dto)
        {
            if (dto == null)
            {
                throw new ArgumentNullException(nameof(dto));
            }

            try
            {
                // TODO: validation!! via FluentValidation
                //if (string.IsNullOrWhiteSpace(dto.FolderId))
                //    throw new ArgumentException("folderScoId can't be empty");

                ScoInfoResult updatedSco =
                    _acProxy.CreateSco(
                        new FolderUpdateItem
                {
                    Name        = dto.Name,
                    Description = dto.Description,
                    FolderId    = dto.FolderId,
                    Type        = ScoType.folder,
                });

                if (!updatedSco.Success)
                {
                    if (updatedSco.Status.Code == StatusCodes.no_access &&
                        updatedSco.Status.SubCode == StatusSubCodes.denied)
                    {
                        return(OperationResultWithData <FolderDto> .Error(Resources.Messages.AccessDenied));
                    }

                    if (updatedSco.Status.Code == StatusCodes.invalid &&
                        updatedSco.Status.SubCode == StatusSubCodes.duplicate &&
                        updatedSco.Status.InvalidField == "name")
                    {
                        return(OperationResultWithData <FolderDto> .Error(Resources.Messages.NameNotUnique));
                    }

                    _logger.Error(updatedSco.Status.GetErrorInfo());
                    return(OperationResultWithData <FolderDto> .Error(updatedSco.Status.GetErrorInfo()));
                }

                dto.ScoId = updatedSco.ScoInfo.ScoId;
                return(dto.ToSuccessResult());
            }
            catch (Exception ex)
            {
                string errorMessage = GetOutputErrorMessage("CreateFolder", ex);
                return(OperationResultWithData <FolderDto> .Error(errorMessage));
            }
        }
Exemple #25
0
        public async Task <OperationResultWithData <OfficeHoursTeacherAvailabilityDto> > AddAvailability(OfficeHours oh, LmsUser lmsUser, OfficeHoursTeacherAvailabilityDto availabilityDto)
        {
            var overlappingSlots = await ValidateSlotsRange(oh, lmsUser.Id, availabilityDto);

            if (overlappingSlots.Any())
            {
                return(OperationResultWithData <OfficeHoursTeacherAvailabilityDto> .Error(
                           "The range of dates overlaps another date range. Please choose another date range."));
            }
            var entity = ConvertFromDto(oh, lmsUser, availabilityDto);

            _availabilityModel.RegisterSave(entity, true);
            return(ConvertToDto(entity).ToSuccessResult());
        }
Exemple #26
0
        public override async Task <OperationResultWithData <LmsUserDTO> > GetUser(Dictionary <string, object> licenseSettings, string lmsUserId, string courseId, ILtiParam extraData = null)
        {
            Guid guid;
            //return GetUsersOldStyle(lmsCompany, courseId, out error)
            //    .FirstOrDefault(u => lmsUserId == (Guid.TryParse(lmsUserId, out guid) ? u.LtiId : u.Id));

            var result = await GetUsers(licenseSettings, courseId, extraData);

            return(result.IsSuccess
                ? result.Data
                   .FirstOrDefault(u => lmsUserId == (Guid.TryParse(lmsUserId, out guid) ? u.LtiId : u.Id))
                   .ToSuccessResult()
                : OperationResultWithData <LmsUserDTO> .Error(result.Message));
        }
Exemple #27
0
        public override async Task <OperationResultWithData <List <LmsUserDTO> > > GetUsers(Dictionary <string, object> licenseSettings, string courseId, ILtiParam param = null)
        {
            if (licenseSettings == null)
            {
                throw new ArgumentNullException(nameof(licenseSettings));
            }

            string error = null;

            string[] userIds = null;

            WebserviceWrapper client = null;
            List <LmsUserDTO> users  = _soapApi.GetUsersForCourse(
                licenseSettings,
                courseId,
                userIds,
                out error,
                ref client);

            if ((users.Count == 0) &&
                error.Return(
                    x => x.IndexOf("ACCESS DENIED", StringComparison.InvariantCultureIgnoreCase) >= 0,
                    false))
            {
                Logger.Warn("GetBlackBoardUsers.AccessDenied. " + error);

                if (client != null)
                {
                    client.logout();
                }
                // NOTE: set to null to re-create session.
                client = null;
                users  = _soapApi.GetUsersForCourse(
                    licenseSettings,
                    courseId,
                    userIds,
                    out error,
                    ref client);
            }

            // NOTE: always call logout
            if (client != null)
            {
                client.logout();
            }

            return(!string.IsNullOrEmpty(error)
                ? OperationResultWithData <List <LmsUserDTO> > .Error(error)
                : users.ToSuccessResult());
        }
Exemple #28
0
        public virtual OperationResultWithData <string> ShareRecording([FromBody] ShareRecordingRequestDto request)
        {
            try
            {
                string link = RecordingsService.UpdateRecording(LmsCompany, GetAdminProvider(), request.RecordingId, request.IsPublic, request.Password);

                return(link.ToSuccessResult());
            }
            catch (Exception ex)
            {
                string errorMessage = GetOutputErrorMessage("ShareRecording", ex);
                return(OperationResultWithData <string> .Error(errorMessage));
            }
        }
Exemple #29
0
        public override async Task <OperationResultWithData <List <LmsUserDTO> > > GetUsers(Dictionary <string, object> licenseSettings,
                                                                                            string courseId, ILtiParam extraData = null)
        {
            if (licenseSettings == null)
            {
                throw new ArgumentNullException(nameof(licenseSettings));
            }

            var result = await _restApiClient.GetUsersForCourseAsync(licenseSettings, courseId);

            return(string.IsNullOrEmpty(result.error)
                ? result.users.ToSuccessResult()
                : OperationResultWithData <List <LmsUserDTO> > .Error(result.error));
        }
Exemple #30
0
 public OperationResult MoveFileOrFolder(string scoId, string destinationFolderScoId)
 {
     try
     {
         var ac     = this.GetUserProvider();
         var helper = new ContentEditControllerHelper(Logger, ac);
         return(helper.MoveSco(scoId, destinationFolderScoId));
     }
     catch (Exception ex)
     {
         string errorMessage = GetOutputErrorMessage("ContentApi-MoveFileOrFolder", ex);
         return(OperationResultWithData <IEnumerable <ScoContentDto> > .Error(errorMessage));
     }
 }