public async Task PostEditPartnershipOrganisationDetails_OrganisationUpdated_SearchCacheShouldBeInvalidated()
        {
            var model = fixture.Build <EditPartnershipOrganisationDetailsViewModel>().WithAutoProperties().Create();

            await controller.EditPartnershipOrganisationDetails(model);

            A.CallTo(() => cache.InvalidateOrganisationSearch()).MustHaveHappenedOnceExactly();
        }
Exemplo n.º 2
0
        public async Task <ActionResult> RegisteredCompanyDetails(RegisteredCompanyDetailsViewModel model)
        {
            SetBreadcrumb(InternalUserActivity.CreateOrganisation);

            if (!ModelState.IsValid)
            {
                var countries = await GetCountries();

                model.Address.Countries = countries;

                return(View(model));
            }

            using (var client = apiClient())
            {
                var request = new CreateOrganisationAdmin()
                {
                    Address            = model.Address,
                    BusinessName       = model.CompanyName,
                    OrganisationType   = model.OrganisationType.GetValueFromDisplayName <OrganisationType>(),
                    RegistrationNumber = model.CompaniesRegistrationNumber,
                    TradingName        = model.BusinessTradingName
                };

                var id = await client.SendAsync(User.GetAccessToken(), request);

                await cache.InvalidateOrganisationSearch();

                return(RedirectToAddAction(id, model.EntityType));
            }
        }
Exemplo n.º 3
0
        public async Task AddAatfPost_ValidViewModel_CacheShouldBeInvalidated()
        {
            AddAatfViewModel viewModel = new AddAatfViewModel()
            {
                SizeValue      = 1,
                StatusValue    = 1,
                OrganisationId = Guid.NewGuid()
            };

            var validationResult = new ValidationResult();

            A.CallTo(() => validationWrapper.Validate(A <string> ._, viewModel)).Returns(validationResult);
            A.CallTo(() => weeeClient.SendAsync(A <string> ._, A <GetApiUtcDate> ._)).Returns(new DateTime(2019, 1, 1));

            await controller.AddAatf(viewModel);

            A.CallTo(() => cache.InvalidateAatfCache(viewModel.OrganisationId)).MustHaveHappenedOnceExactly();
            A.CallTo(() => cache.InvalidateOrganisationSearch()).MustHaveHappened(Repeated.Exactly.Once);
        }
Exemplo n.º 4
0
        public async Task <ActionResult> EditRegisteredCompanyOrganisationDetails(EditRegisteredCompanyOrganisationDetailsViewModel model)
        {
            await SetBreadcrumb(model.SchemeId, model.AatfId, model.OrgId, model.FacilityType);

            if (!ModelState.IsValid)
            {
                using (var client = apiClient())
                {
                    model.BusinessAddress.Countries = await client.SendAsync(User.GetAccessToken(), new GetCountries(false));
                }
                return(View(model));
            }

            using (var client = apiClient())
            {
                var orgData = new OrganisationData
                {
                    Id = model.OrgId,
                    OrganisationType          = model.OrganisationType,
                    CompanyRegistrationNumber = model.CompaniesRegistrationNumber,
                    TradingName     = model.BusinessTradingName,
                    Name            = model.CompanyName,
                    BusinessAddress = model.BusinessAddress,
                };

                await client.SendAsync(User.GetAccessToken(), new UpdateOrganisationDetails(orgData));

                await cache.InvalidateOrganisationSearch();
            }

            if (model.SchemeId.HasValue)
            {
                return(RedirectScheme(model.SchemeId.Value));
            }

            if (model.AatfId.HasValue)
            {
                return(RedirectToAatf(model.AatfId.Value));
            }

            return(View(model));
        }
Exemplo n.º 5
0
        public async Task <ActionResult> Delete(DeleteViewModel viewModel)
        {
            using (var client = apiClient())
            {
                await client.SendAsync(User.GetAccessToken(), new DeleteAnAatf(viewModel.AatfId, viewModel.OrganisationId));

                await cache.InvalidateOrganisationSearch();

                await cache.InvalidateAatfCache(viewModel.OrganisationId);

                return(RedirectToAction("ManageAatfs", new { facilityType = viewModel.FacilityType }));
            }
        }
        public async Task RegisteredCompanyDetailsPost_InvalidateCacheMustBeRun()
        {
            var viewModel = new RegisteredCompanyDetailsViewModel
            {
                BusinessTradingName         = "Company",
                OrganisationType            = "Registered company",
                CompaniesRegistrationNumber = "1234567",
                CompanyName = "Name",
                Address     = { Countries = countries }
            };

            await controller.RegisteredCompanyDetails(viewModel);

            A.CallTo(() => cache.InvalidateOrganisationSearch()).MustHaveHappened(Repeated.Exactly.Once);
        }
Exemplo n.º 7
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 }));
            }
        }
Exemplo n.º 8
0
        public async Task <ActionResult> EditScheme(Guid schemeId, SchemeViewModelBase model)
        {
            if (model.Status == SchemeStatus.Rejected)
            {
                return(RedirectToAction("ConfirmRejection", new { schemeId }));
            }

            if (model.Status == SchemeStatus.Withdrawn)
            {
                return(RedirectToAction("ConfirmWithdrawn", new { schemeId }));
            }

            model.CompetentAuthorities = await GetCompetentAuthorities();

            if (!ModelState.IsValid)
            {
                model = await SetSchemeStatusAndCompetentAuthorities(schemeId, model);
                await SetBreadcrumb(schemeId, InternalUserActivity.ManageScheme);

                return(View(model));
            }

            CreateOrUpdateSchemeInformationResult result;

            using (var client = apiClient())
            {
                UpdateSchemeInformation request = new UpdateSchemeInformation(
                    schemeId,
                    model.SchemeName,
                    model.ApprovalNumber,
                    model.IbisCustomerReference,
                    model.ObligationType.Value,
                    model.CompetentAuthorityId,
                    model.Status);

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

                await cache.InvalidateSchemeCache(schemeId);

                await cache.InvalidateOrganisationSearch();
            }

            switch (result.Result)
            {
            case CreateOrUpdateSchemeInformationResult.ResultType.Success:
                return(RedirectToAction("Overview", new { schemeId }));

            case CreateOrUpdateSchemeInformationResult.ResultType.ApprovalNumberUniquenessFailure:
            {
                ModelState.AddModelError("ApprovalNumber", "Approval number already exists");

                await SetBreadcrumb(schemeId, InternalUserActivity.ManageScheme);

                model = await SetSchemeStatusAndCompetentAuthorities(schemeId, model);

                return(View(model));
            }

            case CreateOrUpdateSchemeInformationResult.ResultType.IbisCustomerReferenceUniquenessFailure:
            {
                string errorMessage = string.Format(
                    "Billing reference \"{0}\" already exists for scheme \"{1}\" ({2})",
                    result.IbisCustomerReferenceUniquenessFailure.IbisCustomerReference,
                    result.IbisCustomerReferenceUniquenessFailure.OtherSchemeName,
                    result.IbisCustomerReferenceUniquenessFailure.OtherSchemeApprovalNumber);

                ModelState.AddModelError("IbisCustomerReference", errorMessage);

                await SetBreadcrumb(schemeId, InternalUserActivity.ManageScheme);

                model = await SetSchemeStatusAndCompetentAuthorities(schemeId, model);

                return(View(model));
            }

            case CreateOrUpdateSchemeInformationResult.ResultType.IbisCustomerReferenceMandatoryForEAFailure:
                ModelState.AddModelError("IbisCustomerReference", "Enter a customer billing reference");

                await SetBreadcrumb(schemeId, InternalUserActivity.ManageScheme);

                model = await SetSchemeStatusAndCompetentAuthorities(schemeId, model);

                return(View(model));

            default:
                throw new NotSupportedException();
            }
        }