public async Task <string> GetDefaultEdFiVersion()
        {
            if (_appSettings.IsStartupModeHosted)
            {
                return(await _cacheProvider.GetOrDefault <string>(CacheKeys.EdFiVersion));
            }

            if (_appSettings.IsStartupModeStandalone)
            {
                return(await _odsApiSettingsProvider.GetEdFiVersion());
            }

            throw new StartupModeNotSupportedException(_appSettings.StartupMode);
        }
Esempio n. 2
0
        public async Task <Staff> GetStaffMemberByEmail(string email)
        {
            var edFiVersion = await _odsApiSettingsProvider.GetEdFiVersion();

            var ods = await _odsApiClientProvider.NewResourcesClient();

            var staffs = await ods.Get <IList <Staffv3> >("staffs", new Dictionary <string, string>
            {
                ["limit"] = "100",
            });

            var foundStaff = staffs
                             .Where(staff => staff.ElectronicMails != null)
                             .Where(staff => staff.ElectronicMails.Any(staffEmail => staffEmail.ElectronicMailAddress.Trim().ToLower().Contains(email.Trim().ToLower())))
                             .FirstOrDefault();

            if (foundStaff == null)
            {
                throw new StaffNotFoundException(email);
            }

            return(foundStaff.MapToStaff());
        }
        public T GetService <T>() where T : IDomainService
        {
            var edFiVersion = _odsApiSettingsProvider.GetEdFiVersion().Result;

            if (typeof(T) == typeof(IAssessmentService))
            {
                return((T)TryGetService(
                           edFiVersion: edFiVersion,
                           serviceName: nameof(IAssessmentService),
                           serviceType: typeof(IAssessmentService),
                           implemenationTypeV2: typeof(AssessmentServiceV2),
                           implemenationTypeV3: typeof(AssessmentServiceV3)
                           ));
            }

            if (typeof(T) == typeof(ICacheRefreshService))
            {
                var service = _serviceProvider.GetService(typeof(CacheRefreshService));

                if (service == null)
                {
                    throw new DomainServiceNotImplementedException(typeof(ICacheRefreshService));
                }

                return((T)service);
            }

            if (typeof(T) == typeof(ICatalogService))
            {
                return((T)TryGetService(
                           edFiVersion: edFiVersion,
                           serviceName: nameof(ICatalogService),
                           serviceType: typeof(ICatalogService),
                           implemenationTypeV2: typeof(CatalogServiceV2),
                           implemenationTypeV3: typeof(CatalogServiceV3)
                           ));
            }

            if (typeof(T) == typeof(IDescriptorService))
            {
                return((T)TryGetService(
                           edFiVersion: edFiVersion,
                           serviceName: nameof(IDescriptorService),
                           serviceType: typeof(IDescriptorService),
                           implemenationTypeV2: typeof(DescriptorServiceV2),
                           implemenationTypeV3: typeof(DescriptorServiceV3)
                           ));
            }

            if (typeof(T) == typeof(IEdFiMapper))
            {
                return((T)TryGetService(
                           edFiVersion: edFiVersion,
                           serviceName: nameof(IEdFiMapper),
                           serviceType: typeof(IEdFiMapper),
                           implemenationTypeV2: typeof(EdFiMapperV2),
                           implemenationTypeV3: typeof(EdFiMapperV3)
                           ));
            }

            if (typeof(T) == typeof(IInterventionService))
            {
                return((T)TryGetService(
                           edFiVersion: edFiVersion,
                           serviceName: nameof(IInterventionService),
                           serviceType: typeof(IInterventionService),
                           implemenationTypeV2: typeof(InterventionServiceV2),
                           implemenationTypeV3: typeof(InterventionServiceV3)
                           ));
            }

            if (typeof(T) == typeof(IMeService))
            {
                return((T)TryGetService(
                           edFiVersion: edFiVersion,
                           serviceName: nameof(IMeService),
                           serviceType: typeof(IMeService),
                           implemenationTypeV2: typeof(MeServiceV2),
                           implemenationTypeV3: typeof(MeServiceV3)
                           ));
            }

            if (typeof(T) == typeof(IScoringAssessmentsService))
            {
                return((T)TryGetService(
                           edFiVersion: edFiVersion,
                           serviceName: nameof(IScoringAssessmentsService),
                           serviceType: typeof(IScoringAssessmentsService),
                           implemenationTypeV2: typeof(ScoringAssessmentsServiceV2),
                           implemenationTypeV3: typeof(ScoringAssessmentsServiceV3)
                           ));
            }

            if (typeof(T) == typeof(IScoringInterventionsService))
            {
                return((T)TryGetService(
                           edFiVersion: edFiVersion,
                           serviceName: nameof(IScoringInterventionsService),
                           serviceType: typeof(IScoringInterventionsService),
                           implemenationTypeV2: typeof(ScoringInterventionsServiceV2),
                           implemenationTypeV3: typeof(ScoringInterventionsServiceV3)
                           ));
            }

            if (typeof(T) == typeof(IStaffsProvider))
            {
                return((T)TryGetService(
                           edFiVersion: edFiVersion,
                           serviceName: nameof(IStaffsProvider),
                           serviceType: typeof(IStaffsProvider),
                           implemenationTypeV2: typeof(StaffsProviderV2),
                           implemenationTypeV3: typeof(StaffsProviderV3)
                           ));
            }

            if (typeof(T) == typeof(IStudentService))
            {
                return((T)TryGetService(
                           edFiVersion: edFiVersion,
                           serviceName: nameof(IStudentService),
                           serviceType: typeof(IStudentService),
                           implemenationTypeV2: typeof(StudentServiceV2),
                           implemenationTypeV3: typeof(StudentServiceV3)
                           ));
            }

            if (typeof(T) == typeof(ITypesService))
            {
                return((T)TryGetService(
                           edFiVersion: edFiVersion,
                           serviceName: nameof(ITypesService),
                           serviceType: typeof(ITypesService),
                           implemenationTypeV2: typeof(TypesServiceV2),
                           implemenationTypeV3: typeof(TypesServiceV3)
                           ));
            }

            throw new DomainServiceNotImplementedException(typeof(T));
        }