public async Task EditPartnershipOrganisationDetails_ModelIsValid_UpdatesDetailsAndRedirectsToSchemeOverview()
        {
            var viewModel = new EditPartnershipOrganisationDetailsViewModel
            {
                OrganisationType    = OrganisationType.SoleTraderOrIndividual,
                BusinessAddress     = new Core.Shared.AddressData(),
                BusinessTradingName = "TradingName",
                OrgId    = Guid.NewGuid(),
                SchemeId = Guid.NewGuid()
            };

            A.CallTo(() => weeeClient.SendAsync(A <string> ._, A <UpdateOrganisationDetails> ._))
            .Returns(true);

            new HttpContextMocker().AttachToController(controller);

            var result = await controller.EditPartnershipOrganisationDetails(viewModel);

            A.CallTo(() => weeeClient.SendAsync(A <string> ._, A <UpdateOrganisationDetails> ._))
            .MustHaveHappened(Repeated.Exactly.Once);

            result.Should().NotBeNull();
            result.Should().BeOfType <RedirectToRouteResult>();

            var redirectResult = (RedirectToRouteResult)result;

            redirectResult.RouteValues["Action"].Should().Be("Overview");
            redirectResult.RouteValues["overviewDisplayOption"].Should().Be(OverviewDisplayOption.OrganisationDetails);
        }
Beispiel #2
0
        public async Task <ActionResult> EditPartnershipOrganisationDetails(Guid?schemeId, Guid orgId, Guid?aatfId, FacilityType?facilityType)
        {
            await SetBreadcrumb(schemeId, aatfId, orgId, facilityType);

            using (var client = apiClient())
            {
                var organisationData = await client.SendAsync(User.GetAccessToken(), new GetInternalOrganisation(orgId));

                if (!organisationData.CanEditOrganisation)
                {
                    return(new HttpForbiddenResult());
                }
                var countries = await client.SendAsync(User.GetAccessToken(), new GetCountries(false));

                var model = new EditPartnershipOrganisationDetailsViewModel
                {
                    OrganisationType    = organisationData.OrganisationType,
                    BusinessTradingName = organisationData.TradingName,
                    BusinessAddress     = organisationData.BusinessAddress,
                    SchemeId            = schemeId,
                    OrgId        = orgId,
                    AatfId       = aatfId,
                    FacilityType = facilityType.GetValueOrDefault()
                };

                model.BusinessAddress.Countries = countries;

                return(View(model));
            }
        }
        public async void EditPartnershipOrganisationDetails_ModelIsInvalid_GetsCountriesAndReturnsDefaultView()
        {
            var countries = new List <CountryData>();

            A.CallTo(() => weeeClient.SendAsync(A <string> ._, A <GetCountries> ._))
            .Returns(countries);

            new HttpContextMocker().AttachToController(controller);

            controller.ModelState.AddModelError("SomeProperty", "IsInvalid");

            var viewModel = new EditPartnershipOrganisationDetailsViewModel
            {
                OrganisationType    = OrganisationType.SoleTraderOrIndividual,
                BusinessAddress     = new Core.Shared.AddressData(),
                BusinessTradingName = "TradingName",
                OrgId    = Guid.NewGuid(),
                SchemeId = Guid.NewGuid()
            };
            var result = await controller.EditPartnershipOrganisationDetails(viewModel);

            A.CallTo(() => weeeClient.SendAsync(A <string> ._, A <GetCountries> ._))
            .MustHaveHappened(Repeated.Exactly.Once);

            countries.Should().BeSameAs(viewModel.BusinessAddress.Countries);

            result.Should().NotBeNull();
            result.Should().BeOfType <ViewResult>();

            var viewResult = (ViewResult)result;

            viewResult.ViewName.Should().BeEmpty();
            viewResult.Model.Should().Be(viewModel);
        }
Beispiel #4
0
        public async Task <ActionResult> EditPartnershipOrganisationDetails(EditPartnershipOrganisationDetailsViewModel 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,
                    TradingName      = model.BusinessTradingName,
                    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));
        }