Ejemplo n.º 1
0
        private async Task <T> PopulateViewModelLists <T>(T viewModel)
            where T : CopyFacilityViewModelBase
        {
            using (var client = apiClient())
            {
                var accessToken = User.GetAccessToken();

                var countries = await client.SendAsync(accessToken, new GetCountries(false));

                viewModel.ContactData.AddressData.Countries = countries;
                viewModel.SiteAddressData.Countries         = countries;
                viewModel.CompetentAuthoritiesList          = await client.SendAsync(accessToken, new GetUKCompetentAuthorities());

                viewModel.PanAreaList = await client.SendAsync(accessToken, new GetPanAreas());

                viewModel.LocalAreaList = await client.SendAsync(accessToken, new GetLocalAreas());

                viewModel.SizeList   = Enumeration.GetAll <AatfSize>();
                viewModel.StatusList = Enumeration.GetAll <AatfStatus>();

                var years = await client.SendAsync(accessToken, new GetAatfComplianceYearsByAatfId(viewModel.AatfId));

                var currentDate = await client.SendAsync(User.GetAccessToken(), new GetApiUtcDate());

                viewModel.ComplianceYearList = new SelectList(AatfHelper.FetchCurrentComplianceYears(currentDate).Except(years.Select(x => (int)x)));
            }

            return(viewModel);
        }
Ejemplo n.º 2
0
        public void GetCurrentComplianceYear_BasedOnCurrentDate(DateTime currentDate, int[] yearList)
        {
            SystemTime.Freeze(new DateTime(currentDate.Year, currentDate.Month, currentDate.Day));
            var value = AatfHelper.FetchCurrentComplianceYears(currentDate, true);

            SystemTime.Unfreeze();
            Assert.Equal(yearList, value.ToArray());
        }
Ejemplo n.º 3
0
        private async Task <ActionResult> AddFacility(AddFacilityViewModelBase viewModel)
        {
            PreventSiteAddressNameValidationErrors();
            SetBreadcrumb(viewModel.FacilityType);
            viewModel = await PopulateViewModelLists(viewModel);

            if (!ModelState.IsValid)
            {
                if (!viewModel.ModelValidated)
                {
                    ModelState.RunCustomValidation(viewModel);
                }

                ModelState.ApplyCustomValidationSummaryOrdering(AddFacilityViewModelBase.ValidationMessageDisplayOrder);
                return(View(nameof(Add), viewModel));
            }

            using (var client = apiClient())
            {
                var result = await validationWrapper.Validate(User.GetAccessToken(), viewModel);

                if (!result.IsValid)
                {
                    ModelState.AddModelError("ApprovalNumber", Constants.ApprovalNumberExistsError);
                    return(View(nameof(Add), viewModel));
                }

                var request = new AddAatf()
                {
                    Aatf           = AatfHelper.CreateFacilityData(viewModel),
                    AatfContact    = viewModel.ContactData,
                    OrganisationId = viewModel.OrganisationId,
                };

                await client.SendAsync(User.GetAccessToken(), request);

                await cache.InvalidateAatfCache(request.OrganisationId);

                await client.SendAsync(User.GetAccessToken(), new CompleteOrganisationAdmin()
                {
                    OrganisationId = viewModel.OrganisationId
                });

                await cache.InvalidateOrganisationSearch();

                return(RedirectToAction("ManageAatfs", "Aatf", new { viewModel.FacilityType }));
            }
        }
Ejemplo n.º 4
0
        private async Task <T> PopulateViewModelLists <T>(T viewModel)
            where T : AddFacilityViewModelBase
        {
            using (var client = apiClient())
            {
                var countries = await GetCountries();

                var organisation = await client.SendAsync(User.GetAccessToken(), new GetOrganisationInfo(viewModel.OrganisationId));

                viewModel.ContactData.AddressData.Countries = countries;
                viewModel.OrganisationName = organisation.OrganisationName;
                viewModel = await PopulateFacilityViewModelLists(viewModel, countries, client, User.GetAccessToken());

                var currentDate = await client.SendAsync(User.GetAccessToken(), new GetApiUtcDate());

                viewModel.ComplianceYearList = new SelectList(AatfHelper.FetchCurrentComplianceYears(currentDate));
            }

            return(viewModel);
        }
Ejemplo n.º 5
0
 private bool IsValidRecordToEdit(DateTime currentDate, int complianceYear)
 {
     return(currentDate.Year > 1 && AatfHelper.FetchCurrentComplianceYears(currentDate, true).Any(x => x.Equals(complianceYear)) ? true : false);
 }