public async Task <ActionResult> EducationOrganizationList()
        {
            var api = await _odsApiFacadeFactory.Create();

            var schools = api.GetAllSchools();
            var localEducationAgencies = api.GetAllLocalEducationAgencies();

            var requiredApiDataExist = (await _odsApiFacadeFactory.Create()).DoesApiDataExist();

            var model = new EducationOrganizationViewModel
            {
                Schools = schools,
                LocalEducationAgencies       = localEducationAgencies,
                ShouldAllowMultipleDistricts = CloudOdsAdminAppSettings.Instance.Mode != ApiMode.DistrictSpecific,
                AddSchoolModel = new AddSchoolModel
                {
                    GradeLevelOptions    = api.GetAllGradeLevels(),
                    StateOptions         = api.GetAllStateAbbreviations(),
                    RequiredApiDataExist = requiredApiDataExist
                },
                AddLocalEducationAgencyModel = new AddLocalEducationAgencyModel
                {
                    LocalEducationAgencyCategoryTypeOptions = api.GetLocalEducationAgencyCategories(),
                    StateOptions         = api.GetAllStateAbbreviations(),
                    RequiredApiDataExist = requiredApiDataExist
                }
            };

            if (CloudOdsAdminAppSettings.Instance.Mode == ApiMode.DistrictSpecific)
            {
                model.AddLocalEducationAgencyModel.LocalEducationAgencyId = OdsInstanceIdentityHelper.GetIdentityValue(_instanceContext.Name);
            }

            return(PartialView("_EducationOrganizations", model));
        }
        public async Task <ApplicationCreateResult> CreateAdminAppInAdminDatabase(string claimSetClaimSetName,
                                                                                  string odsInstanceName, string odsInstanceVersion, ApiMode apiMode)
        {
            var applicationName = odsInstanceName.GetAdminApplicationName();

            var existingApplication = await UsersContext.Applications.SingleOrDefaultAsync(x =>
                                                                                           x.ApplicationName.Equals(applicationName,
                                                                                                                    StringComparison.InvariantCultureIgnoreCase));

            if (existingApplication != null)
            {
                return(new ApplicationCreateResult
                {
                    Application = existingApplication
                });
            }

            var result = new ApplicationCreateResult
            {
                Application = new Application
                {
                    ApplicationName       = applicationName,
                    Vendor                = CreateEdFiVendor(),
                    ClaimSetName          = claimSetClaimSetName,
                    OdsInstance           = CreateOdsInstance(odsInstanceName, odsInstanceVersion),
                    OperationalContextUri = OperationalContext.DefaultOperationalContextUri
                }
            };

            var apiClientFactory = new ApiClientFactory(_securePackedHashProvider, _hashConfigurationProvider);

            var apiWithCredentials = apiClientFactory.GetApiClientAndCredentials(CloudOdsEnvironment.Production,
                                                                                 applicationName);

            result.Application.ApiClients.Add(apiWithCredentials.ApiClient);
            result.ProductionKeyAndSecret = apiWithCredentials.ApiCredentials;

            if (apiMode.Equals(ApiMode.DistrictSpecific))
            {
                var edOrgId = OdsInstanceIdentityHelper.GetIdentityValue(odsInstanceName);

                var applicationEdOrgs = new List <ApplicationEducationOrganization>
                {
                    new ApplicationEducationOrganization
                    {
                        Clients = new List <ApiClient> {
                            apiWithCredentials.ApiClient
                        },
                        EducationOrganizationId = edOrgId
                    }
                };

                result.Application.ApplicationEducationOrganizations =
                    new List <ApplicationEducationOrganization>(applicationEdOrgs);
            }

            UsersContext.Applications.Add(result.Application);

            return(result);
        }
        public void ShouldReturnExpectedYear()
        {
            const int expectedYearValue = 2019;

            var returnedYearValue = OdsInstanceIdentityHelper.GetIdentityValue($"EdFi_Ods_{expectedYearValue}");

            returnedYearValue.ShouldBe(expectedYearValue);
        }
        public void ShouldReturnExpectedEdOrgId()
        {
            const int expectedEdOrgId = 255901;

            var returnedEdOrgId = OdsInstanceIdentityHelper.GetIdentityValue($"EdFi_Ods_{expectedEdOrgId}");

            returnedEdOrgId.ShouldBe(expectedEdOrgId);
        }
Example #5
0
        public async Task CreateAcademicBenchmarksConnectAppInAdminDatabase(ApiMode apiMode)
        {
            var applicationName     = $"{_instanceContext.Name}_{CloudsOdsAcademicBenchmarksConnectApp.ApplicationName}";
            var existingApplication = _usersContext.Applications.SingleOrDefault(x =>
                                                                                 x.ApplicationName.Equals(applicationName,
                                                                                                          StringComparison.InvariantCultureIgnoreCase));

            if (existingApplication != null)
            {
                return;
            }

            var instance = _usersContext.OdsInstances.SingleOrDefault(x =>
                                                                      x.Name.Equals(_instanceContext.Name, StringComparison.InvariantCultureIgnoreCase));

            var newApplication = new Application
            {
                ApplicationName       = applicationName,
                Vendor                = CreateCerticaVendor(),
                OdsInstance           = instance,
                ClaimSetName          = CloudsOdsAcademicBenchmarksConnectApp.DefaultClaimSet,
                OperationalContextUri = OperationalContext.DefaultOperationalContextUri
            };

            await CreateAndSaveNewApiClients(newApplication);

            if (apiMode.Equals(ApiMode.DistrictSpecific))
            {
                var edOrgId = OdsInstanceIdentityHelper.GetIdentityValue(_instanceContext.Name);
                newApplication.ApplicationEducationOrganizations =
                    new List <ApplicationEducationOrganization>
                {
                    new ApplicationEducationOrganization
                    {
                        Clients = newApplication.ApiClients,
                        EducationOrganizationId = edOrgId
                    }
                };
            }

            _usersContext.Applications.Add(newApplication);
        }
Example #6
0
        public async Task <ActionResult> AddLocalEducationAgencyModal()
        {
            var api = await _odsApiFacadeFactory.Create();

            var localEducationAgencyCategoryOptions = api.GetLocalEducationAgencyCategories();
            var stateOptions         = api.GetAllStateAbbreviations();
            var requiredApiDataExist = (await _odsApiFacadeFactory.Create()).DoesApiDataExist();

            var model = new AddLocalEducationAgencyModel
            {
                LocalEducationAgencyCategoryTypeOptions = localEducationAgencyCategoryOptions,
                StateOptions         = stateOptions,
                RequiredApiDataExist = requiredApiDataExist
            };

            if (CloudOdsAdminAppSettings.Instance.Mode == ApiMode.DistrictSpecific)
            {
                model.LocalEducationAgencyId = OdsInstanceIdentityHelper.GetIdentityValue(_instanceContext.Name);
            }

            return(PartialView("_AddLocalEducationAgencyModal", model));
        }