private async Task <ActionResult> SaveValidatedOrgansation(ProviderEnrichmentModel enrichmentModel, string providerCode) { var postModel = new UcasProviderEnrichmentPostModel { EnrichmentModel = enrichmentModel }; await _manageApi.SaveProviderEnrichment(providerCode, postModel); TempData["MessageType"] = "success"; TempData["MessageTitle"] = "Your changes have been saved"; TempData["MessageBodyHtml"] = "<p class=\"govuk-body\">Preview any course to see how it will look to applicants.</p>"; return(RedirectToAction("Details", "Organisation", new { providerCode = providerCode })); }
private string MapAddress(ProviderEnrichmentModel orgEnrichmentModel) { var addressFragments = new List <string> { orgEnrichmentModel.Address1, orgEnrichmentModel.Address2, orgEnrichmentModel.Address3, orgEnrichmentModel.Address4 }.Where(x => !string.IsNullOrWhiteSpace(x)); var postCode = orgEnrichmentModel.Postcode ?? ""; return(addressFragments.Any() ? String.Join("\n", addressFragments) + "\n" + postCode : postCode); }
public void MergeIntoEnrichmentModel(ref ProviderEnrichmentModel enrichmentModel) { if (enrichmentModel == null) { enrichmentModel = new ProviderEnrichmentModel(); } enrichmentModel.Email = EmailAddress; enrichmentModel.Telephone = Telephone; enrichmentModel.Website = Url; enrichmentModel.Address1 = Addr1; enrichmentModel.Address2 = Addr2; enrichmentModel.Address3 = Addr3; enrichmentModel.Address4 = Addr4; enrichmentModel.Postcode = Postcode; }
public void MergeIntoEnrichmentModel(ref ProviderEnrichmentModel enrichmentModel) { if (enrichmentModel == null) { enrichmentModel = new ProviderEnrichmentModel(); } var aboutTrainingProviders = new List <AccreditingProviderEnrichment>( AboutTrainingProviders.Select(x => new AccreditingProviderEnrichment { UcasProviderCode = x.ProviderCode, Description = x.Description })); enrichmentModel.TrainWithUs = TrainWithUs; enrichmentModel.AccreditingProviderEnrichments = aboutTrainingProviders; enrichmentModel.TrainWithDisability = TrainWithDisability; }
public UcasProviderEnrichmentPostModel() { EnrichmentModel = new ProviderEnrichmentModel(); }
private async Task <List <TrainingProviderViewModel> > MergeTrainingProviderViewModels(string providerCode, ProviderEnrichmentModel enrichmentModel, IEnumerable <TrainingProviderViewModel> fromModel = null) { var ucasData = await _manageApi.GetCoursesOfProvider(providerCode); var accreditingProviders = ucasData .Where(x => false == string.Equals(x.AccreditingProvider?.ProviderCode, providerCode, StringComparison.InvariantCultureIgnoreCase) && false == string.IsNullOrWhiteSpace(x.AccreditingProvider?.ProviderCode)) .Distinct(new AccreditingProviderCodeComparer()).ToList(); var accreditingProviderEnrichments = enrichmentModel?.AccreditingProviderEnrichments ?? new List <AccreditingProviderEnrichment>(); var result = accreditingProviders.Select(x => { var description = accreditingProviderEnrichments.FirstOrDefault(TrainingProviderMatchesProviderCourse(x))?.Description ?? ""; var aboutTrainingProviders = (fromModel ?? new List <TrainingProviderViewModel>()); var newAccreditingProviderModel = aboutTrainingProviders.FirstOrDefault( atp => (atp.ProviderCode.Equals(x.AccreditingProvider?.ProviderCode, StringComparison.InvariantCultureIgnoreCase))); if (newAccreditingProviderModel != null) { // empty descriptions get bound as `null` by ASP.NET MVC model binding description = newAccreditingProviderModel.Description ?? ""; } var tpvm = new TrainingProviderViewModel() { ProviderName = x.AccreditingProvider?.ProviderName, ProviderCode = x.AccreditingProvider?.ProviderCode, Description = description }; return(tpvm); }) .ToList(); return(result); }
public void AboutPost_ModelState_WordCount() { var providerCode = "PROVIDERCODE"; var exceed100Words = ""; for (int i = 0; i < 101; i++) { exceed100Words += i + " "; } var providerName = "ProviderName"; var viewModel = new OrganisationViewModelForAbout { AboutTrainingProviders = new List <TrainingProviderViewModel>() { new TrainingProviderViewModel { Description = exceed100Words, ProviderName = providerName, ProviderCode = providerCode + 1 } } }; var providerCourses = new List <Course> { new Course { }, new Course { AccreditingProvider = new GovUk.Education.ManageCourses.Domain.Models.Provider { ProviderCode = providerCode.ToUpperInvariant() } }, new Course { AccreditingProvider = new GovUk.Education.ManageCourses.Domain.Models.Provider { ProviderCode = providerCode.ToLowerInvariant() } }, new Course { AccreditingProvider = new GovUk.Education.ManageCourses.Domain.Models.Provider { ProviderCode = providerCode } }, new Course { AccreditingProvider = new GovUk.Education.ManageCourses.Domain.Models.Provider { ProviderCode = providerCode + 1, ProviderName = providerName } }, new Course { AccreditingProvider = new GovUk.Education.ManageCourses.Domain.Models.Provider { ProviderCode = providerCode + 2 } }, }; var apiMock = new Mock <IManageApi>(); apiMock.Setup(x => x.GetCoursesOfProvider(providerCode)) .ReturnsAsync(providerCourses); var enrichmentModel = new ProviderEnrichmentModel { AccreditingProviderEnrichments = new List <AccreditingProviderEnrichment> { } }; var ucasProviderEnrichmentGetModel = new UcasProviderEnrichmentGetModel() { EnrichmentModel = enrichmentModel }; apiMock.Setup(x => x.GetProviderSummaries()) .ReturnsAsync(new List <ProviderSummary> { new ProviderSummary() }); apiMock.Setup(x => x.GetProviderEnrichment(providerCode)) .ReturnsAsync(ucasProviderEnrichmentGetModel); var objectValidator = new Mock <IObjectModelValidator>(); objectValidator.Setup(o => o.Validate(It.IsAny <ActionContext>(), It.IsAny <ValidationStateDictionary>(), It.IsAny <string>(), It.IsAny <Object>())); var frontendUrlMock = new Mock <IFrontendUrlService>(); var controller = new OrganisationController(apiMock.Object, frontendUrlMock.Object); controller.ObjectValidator = objectValidator.Object; controller.TempData = new Mock <ITempDataDictionary>().Object; Assert.IsFalse(controller.ModelState.Any()); Assert.IsTrue(controller.ModelState.IsValid); var result = controller.AboutPost(providerCode, viewModel).Result; Assert.IsTrue(controller.ModelState.Any()); Assert.AreEqual($"Reduce word count for {providerName}", controller.ModelState["AboutTrainingProviders_0__Description"].Errors.First().ErrorMessage); Assert.IsFalse(controller.ModelState.IsValid); var viewResult = result as ViewResult; var organisationViewModel = viewResult.ViewData.Model as OrganisationViewModelForAbout; Assert.IsNotNull(viewResult); Assert.AreEqual(exceed100Words, organisationViewModel.AboutTrainingProviders.First(x => x.ProviderCode == providerCode + 1).Description); Assert.AreEqual(providerName, organisationViewModel.AboutTrainingProviders.First(x => x.ProviderCode == providerCode + 1).ProviderName); }
public async Task DetailsPost_PublishOrganisation_WhenApiReturnsTrue() { var providerCode = "PROVIDERCODE"; var viewModel = new OrganisationViewModel { AboutTrainingProviders = new List <TrainingProviderViewModel>() }; var providerName = "ProviderName"; var providerCourses = new List <Course> { new Course { }, new Course { AccreditingProvider = new GovUk.Education.ManageCourses.Domain.Models.Provider { ProviderCode = providerCode.ToUpperInvariant() } }, new Course { AccreditingProvider = new GovUk.Education.ManageCourses.Domain.Models.Provider { ProviderCode = providerCode.ToLowerInvariant() } }, new Course { AccreditingProvider = new GovUk.Education.ManageCourses.Domain.Models.Provider { ProviderCode = providerCode } }, new Course { AccreditingProvider = new GovUk.Education.ManageCourses.Domain.Models.Provider { ProviderCode = providerCode + 1, ProviderName = providerName } }, new Course { AccreditingProvider = new GovUk.Education.ManageCourses.Domain.Models.Provider { ProviderCode = providerCode + 2 } }, }; var apiMock = new Mock <IManageApi>(); apiMock.Setup(x => x.GetProviderSummary(providerCode)) .ReturnsAsync(new ProviderSummary { ProviderCode = providerCode, ProviderName = providerName }); apiMock.Setup(x => x.GetCoursesOfProvider(providerCode)) .ReturnsAsync(providerCourses); var enrichmentModel = new ProviderEnrichmentModel { AccreditingProviderEnrichments = new List <AccreditingProviderEnrichment>() }; var ucasProviderEnrichmentGetModel = new UcasProviderEnrichmentGetModel() { EnrichmentModel = enrichmentModel }; apiMock.Setup(x => x.GetProviderEnrichment(providerCode)) .ReturnsAsync(ucasProviderEnrichmentGetModel); var objectValidator = new Mock <IObjectModelValidator>(); objectValidator.Setup(o => o.Validate(It.IsAny <ActionContext>(), It.IsAny <ValidationStateDictionary>(), It.IsAny <string>(), It.IsAny <Object>())); apiMock.Setup(x => x.PublishAllCoursesOfProviderToSearchAndCompare(providerCode)) .ReturnsAsync(true); var frontendUrlMock = new Mock <IFrontendUrlService>(); var controller = new OrganisationController(apiMock.Object, frontendUrlMock.Object); controller.ObjectValidator = objectValidator.Object; controller.TempData = new Mock <ITempDataDictionary>().Object; var result = await controller.DetailsPost(providerCode, viewModel); var actionResult = result as RedirectToActionResult; Assert.IsNotNull(actionResult); Assert.AreEqual("Details", actionResult.ActionName); Assert.AreEqual(providerCode, actionResult.RouteValues[providerCode]); }
public void DetailsPost_PublishOrganisation_WhenApiReturnsFalse() { var providerCode = "PROVIDERCODE"; var providerName = "ProviderName"; var viewModel = new OrganisationViewModel { AboutTrainingProviders = new List <TrainingProviderViewModel>() }; var providerCourses = new List <Course> { new Course { }, new Course { AccreditingProvider = new GovUk.Education.ManageCourses.Domain.Models.Provider { ProviderCode = providerCode.ToUpperInvariant() } }, new Course { AccreditingProvider = new GovUk.Education.ManageCourses.Domain.Models.Provider { ProviderCode = providerCode.ToLowerInvariant() } }, new Course { AccreditingProvider = new GovUk.Education.ManageCourses.Domain.Models.Provider { ProviderCode = providerCode } }, new Course { AccreditingProvider = new GovUk.Education.ManageCourses.Domain.Models.Provider { ProviderCode = providerCode + 1, ProviderName = providerName } }, new Course { AccreditingProvider = new GovUk.Education.ManageCourses.Domain.Models.Provider { ProviderCode = providerCode + 2 } }, }; var apiMock = new Mock <IManageApi>(); apiMock.Setup(x => x.GetProviderSummary(providerCode)) .ReturnsAsync(new ProviderSummary { ProviderCode = providerCode, ProviderName = providerName }); apiMock.Setup(x => x.GetCoursesOfProvider(providerCode)) .ReturnsAsync(providerCourses); var enrichmentModel = new ProviderEnrichmentModel { AccreditingProviderEnrichments = new List <AccreditingProviderEnrichment> { } }; var ucasProviderEnrichmentGetModel = new UcasProviderEnrichmentGetModel() { EnrichmentModel = enrichmentModel }; apiMock.Setup(x => x.GetProviderEnrichment(providerCode)) .ReturnsAsync(ucasProviderEnrichmentGetModel); var objectValidator = new Mock <IObjectModelValidator>(); objectValidator.Setup(o => o.Validate(It.IsAny <ActionContext>(), It.IsAny <ValidationStateDictionary>(), It.IsAny <string>(), It.IsAny <Object>())); var frontendUrlMock = new Mock <IFrontendUrlService>(); var controller = new OrganisationController(apiMock.Object, frontendUrlMock.Object); controller.ObjectValidator = objectValidator.Object; controller.TempData = new Mock <ITempDataDictionary>().Object; Assert.ThrowsAsync <InvalidOperationException>(async() => await controller.DetailsPost(providerCode, viewModel)); }
protected override void Setup() { var accreditingInstitution = new Provider { ProviderName = "Trilby University", // Universities can accredit courses provided by schools / SCITTs ProviderCode = AccreditingInstCode, RecruitmentCycle = CurrentRecruitmentCycle, }; Context.Add(accreditingInstitution); const string providerInstCode = "HNY1"; const string crseCode = "TK101"; _ucasInstitution = new Provider { ProviderName = "Honey Lane School", // This is a school so has to have a university accredit the courses it offers ProviderCode = providerInstCode, Courses = new List <Course> { new Course { CourseCode = crseCode, Name = "Conscious control of telekenisis", AccreditingProvider = accreditingInstitution, } }, RecruitmentCycle = CurrentRecruitmentCycle, }; Context.Add(_ucasInstitution); var user = new User { Email = Email, }; Context.Add(user); var user2 = new User { Email = Email2, }; Context.Add(user); //create the organisation and add user1 and user2 to it var org = new Organisation { Name = "Bucks Mega Org", OrgId = "BMO1", OrganisationUsers = new List <OrganisationUser> { new OrganisationUser { User = user, }, new OrganisationUser { User = user2, }, }, OrganisationProviders = new List <OrganisationProvider> { new OrganisationProvider { Provider = _ucasInstitution, }, } }; Context.Add(org); Context.SaveChanges(); //now add the enrichment model with user1 var enrichmentModel = new ProviderEnrichmentModel { TrainWithDisability = TrainWithDisabilityText, TrainWithUs = TrainWithUsText, AccreditingProviderEnrichments = new List <AccreditingProviderEnrichment> { new AccreditingProviderEnrichment { UcasProviderCode = AccreditingInstCode, Description = "xcvxcvxcv", } } }; var jsonSerializerSettings = new JsonSerializerSettings { MissingMemberHandling = MissingMemberHandling.Ignore, NullValueHandling = NullValueHandling.Ignore }; var content = JsonConvert.SerializeObject(enrichmentModel, jsonSerializerSettings); var enrichment = new ProviderEnrichment { ProviderCode = ProviderInstCode, CreatedAt = DateTime.UtcNow, UpdatedAt = DateTime.UtcNow, LastPublishedAt = null, CreatedByUser = user, UpdatedByUser = user, Status = EnumStatus.Draft, JsonData = content, }; _ucasInstitution.ProviderEnrichments.Add(enrichment); Context.SaveChanges(); }
private string GetAccreditingProviderEnrichment(string accreditingProviderCode, ProviderEnrichmentModel enrichmentModel) { if (string.IsNullOrWhiteSpace(accreditingProviderCode)) { return(""); } if (enrichmentModel.AccreditingProviderEnrichments == null) { return(""); } var enrichment = enrichmentModel.AccreditingProviderEnrichments.FirstOrDefault(x => x.UcasProviderCode == accreditingProviderCode); if (enrichment == null) { return(""); } return(enrichment.Description); }
public SearchAndCompare.Domain.Models.Course MapToSearchAndCompareCourse(Domain.Models.Provider ucasProviderData, Domain.Models.Course ucasCourseData, ProviderEnrichmentModel providerEnrichmentModel, CourseEnrichmentModel courseEnrichmentModel) { ucasProviderData = ucasProviderData ?? new Domain.Models.Provider(); ucasCourseData = ucasCourseData ?? new Domain.Models.Course(); var courseSites = ucasCourseData.PublishableSites ?? new ObservableCollection <CourseSite>(); providerEnrichmentModel = providerEnrichmentModel ?? new ProviderEnrichmentModel(); courseEnrichmentModel = courseEnrichmentModel ?? new CourseEnrichmentModel(); var useUcasContact = string.IsNullOrWhiteSpace(providerEnrichmentModel.Email) && string.IsNullOrWhiteSpace(providerEnrichmentModel.Website) && string.IsNullOrWhiteSpace(providerEnrichmentModel.Address1) && string.IsNullOrWhiteSpace(providerEnrichmentModel.Address2) && string.IsNullOrWhiteSpace(providerEnrichmentModel.Address3) && string.IsNullOrWhiteSpace(providerEnrichmentModel.Address4) && string.IsNullOrWhiteSpace(providerEnrichmentModel.Postcode); var subjectStrings = ucasCourseData?.CourseSubjects != null ? subjectMapper.GetSubjectList(ucasCourseData.Name, ucasCourseData.CourseSubjects.Select(x => x.Subject.SubjectName)) : new List <string>(); var subjects = new Collection <SearchAndCompare.Domain.Models.Joins.CourseSubject>(subjectStrings.Select(subject => new SearchAndCompare.Domain.Models.Joins.CourseSubject { Subject = new SearchAndCompare.Domain.Models.Subject { Name = subject } }).ToList()); var provider = new SearchAndCompare.Domain.Models.Provider { Name = ucasProviderData.ProviderName, ProviderCode = ucasProviderData.ProviderCode }; var accreditingProvider = ucasCourseData.AccreditingProvider == null ? null : new SearchAndCompare.Domain.Models.Provider { Name = ucasCourseData.AccreditingProvider.ProviderName, ProviderCode = ucasCourseData.AccreditingProvider.ProviderCode }; var routeName = ucasCourseData.Route; var isSalaried = string.Equals(ucasCourseData?.ProgramType, "ss", StringComparison.InvariantCultureIgnoreCase) || string.Equals(ucasCourseData?.ProgramType, "ta", StringComparison.InvariantCultureIgnoreCase); var fees = courseEnrichmentModel.FeeUkEu.HasValue ? new Fees { Uk = (int)(courseEnrichmentModel.FeeUkEu ?? 0), Eu = (int)(courseEnrichmentModel.FeeUkEu ?? 0), International = (int)(courseEnrichmentModel.FeeInternational ?? 0), } : new Fees(); var address = useUcasContact ? MapAddress(ucasProviderData) : MapAddress(providerEnrichmentModel); var mappedCourse = new SearchAndCompare.Domain.Models.Course { ProviderLocation = new Location { Address = address }, Duration = MapCourseLength(courseEnrichmentModel.CourseLength), StartDate = ucasCourseData.StartDate, Name = ucasCourseData.Name, ProgrammeCode = ucasCourseData.CourseCode, Provider = provider, AccreditingProvider = accreditingProvider, IsSen = ucasCourseData.IsSend, Route = new Route { Name = routeName, IsSalaried = isSalaried }, IncludesPgce = MapQualification(ucasCourseData.Qualification), HasVacancies = ucasCourseData.HasVacancies, Campuses = new Collection <SearchAndCompare.Domain.Models.Campus>( courseSites .Select(school => new SearchAndCompare.Domain.Models.Campus { Name = school.Site.LocationName, CampusCode = school.Site.Code, Location = new Location { Address = MapAddress(school.Site) }, VacStatus = school.VacStatus } ).ToList()), CourseSubjects = subjects, Fees = fees, IsSalaried = isSalaried, ContactDetails = new Contact { Phone = useUcasContact ? ucasProviderData.Telephone : providerEnrichmentModel.Telephone, Email = useUcasContact ? ucasProviderData.Email : providerEnrichmentModel.Email, Website = useUcasContact ? ucasProviderData.Url : providerEnrichmentModel.Website, Address = address }, ApplicationsAcceptedFrom = courseSites.Select(x => x.ApplicationsAcceptedFrom).Where(x => x.HasValue) .OrderBy(x => x.Value) .FirstOrDefault(), FullTime = ucasCourseData.StudyMode == "P" ? VacancyStatus.NA : VacancyStatus.Vacancies, PartTime = ucasCourseData.StudyMode == "F" ? VacancyStatus.NA : VacancyStatus.Vacancies, Mod = ucasCourseData.TypeDescription, }; mappedCourse.DescriptionSections = new Collection <CourseDescriptionSection>(); mappedCourse.DescriptionSections.Add(new CourseDescriptionSection { //TODO move the CourseDetailsSections constants into SearchAndCompare.Domain.Models // but this will work ftm Name = "about this training programme",//CourseDetailsSections.AboutTheCourse, Text = courseEnrichmentModel.AboutCourse }); mappedCourse.DescriptionSections.Add(new CourseDescriptionSection { Name = "interview process",//CourseDetailsSections.InterviewProcess, Text = courseEnrichmentModel.InterviewProcess }); mappedCourse.DescriptionSections.Add(new CourseDescriptionSection { Name = "about fees",//CourseDetailsSections.AboutFees, Text = courseEnrichmentModel.FeeDetails }); mappedCourse.DescriptionSections.Add(new CourseDescriptionSection { Name = "about salary",//CourseDetailsSections.AboutSalary, Text = courseEnrichmentModel.SalaryDetails }); mappedCourse.DescriptionSections.Add(new CourseDescriptionSection { Name = "entry requirements",//CourseDetailsSections.EntryRequirementsQualifications, Text = courseEnrichmentModel.Qualifications }); mappedCourse.DescriptionSections.Add(new CourseDescriptionSection { Name = "entry requirements personal qualities",//CourseDetailsSections.EntryRequirementsPersonalQualities, Text = courseEnrichmentModel.PersonalQualities }); mappedCourse.DescriptionSections.Add(new CourseDescriptionSection { Name = "entry requirements other",//CourseDetailsSections.EntryRequirementsOther, Text = courseEnrichmentModel.OtherRequirements }); mappedCourse.DescriptionSections.Add(new CourseDescriptionSection { Name = "financial support",//CourseDetailsSections.FinancialSupport, Text = courseEnrichmentModel.FinancialSupport }); mappedCourse.DescriptionSections.Add(new CourseDescriptionSection { Name = "about school placements",//CourseDetailsSections.AboutSchools, Text = courseEnrichmentModel.HowSchoolPlacementsWork }); mappedCourse.DescriptionSections.Add(new CourseDescriptionSection { Name = "about this training provider",//CourseDetailsSections.AboutTheProvider, Text = providerEnrichmentModel.TrainWithUs }); mappedCourse.DescriptionSections.Add(new CourseDescriptionSection { Name = "about this training provider accrediting",//CourseDetailsSections.AboutTheAccreditingProvider, Text = GetAccreditingProviderEnrichment(ucasCourseData?.AccreditingProvider?.ProviderCode, providerEnrichmentModel) }); mappedCourse.DescriptionSections.Add(new CourseDescriptionSection { Name = "training with disabilities",//CourseDetailsSections.TrainWithDisabilities, Text = providerEnrichmentModel.TrainWithDisability }); return(mappedCourse); }