public async Task <IActionResult> Index(string uri) { var regionResource = await _loader.Load <Resource, RegionModel>(uri); var regions = regionResource.GetRegions(); return(View(new RegionViewModel { Regions = regions, RegionUri = uri })); }
public async Task <IActionResult> Index(string uri) { var model = await _modelLoader.Load <Resource, PreferencesModel>(uri); return(View(new PreferencesViewModel { PreferencesUri = uri, PaymentMethods = model.GetPaymentMethods(), ResultsOrders = model.GetResultsOrders(), TariffFilterOptions = model.GetTariffFilterOptions() })); }
private async Task <FutureSupplyViewModel> GetFutureSupplyViewModel(string uri, IEnumerable <Error> errors = null) { var futureSupply = await _modelLoader.Load <Resource, FutureSupplyModel>(uri); var futureSupplies = await _modelLoader.Load <FutureSupplies, ResultsModel>(futureSupply.ResultsUri); return(new FutureSupplyViewModel { DualFuelEnergySupplies = futureSupplies.GetDualFuelEnergySupplies(), PaymentMethods = futureSupplies.GetPaymentMethods(), FutureSupplyUri = uri, Errors = errors?.Select(x => x.Message.Text) ?? Enumerable.Empty <string>() }); }
public async Task <IActionResult> Index(string uri, string transferUri) { var switchResource = await _modelLoader.Load <SwitchResource, SwitchModel>(uri); var usageModel = await _modelLoader.Load <Resource, CurrentUsageModel>(switchResource.CurrentUsageUri); var currentUsageEstimatorValueMap = new CurrentUsageEstimatorValueMap(switchResource, usageModel); var viewModel = new SwitchViewModel { Postcode = switchResource.Postcode, GasContractExpiryDate = switchResource.GasContractExpiryDate?.ToString("dd/MM/yyyy"), GasPaymentMethod = switchResource.GasPaymentMethod, GasSupplyName = switchResource.GasSupplyName, GasTariff = switchResource.GasTariff, ElectricityContractExpiryDate = switchResource.ElectricityContractExpiryDate?.ToString("dd/MM/yyyy"), ElectricityPaymentMethod = switchResource.ElectricityPaymentMethod, ElectricitySupplyName = switchResource.ElectricitySupplyName, ElectricityTariff = switchResource.ElectricityTariff, ElectricityEcomony7 = switchResource.ElectricityEcomony7.ToString(), NightPercentUsage = usageModel.GetNightPercentUsage(), GasUsageType = switchResource.GetGasUsageType(), ElectricityUsageType = switchResource.GetElectricityUsageType(), GasUsageSimpleEstimator = currentUsageEstimatorValueMap.GasSimpleEstimator(), ElectricityUsageSimpleEstimator = currentUsageEstimatorValueMap.ElectricitySimpleEstimator(), GasHouseType = currentUsageEstimatorValueMap.GasHouseTypeName(), GasNumberOfBedrooms = currentUsageEstimatorValueMap.GasNumberOfBedrooms(), GasMainCookingSource = currentUsageEstimatorValueMap.GasMainCookingSource(), GasCookingFrequency = currentUsageEstimatorValueMap.GasCookingFrequency(), GasCentralHeating = currentUsageEstimatorValueMap.GasCentralHeating(), GasNumberOfOccupants = currentUsageEstimatorValueMap.GasNumberOfOccupants(), GasInsulation = currentUsageEstimatorValueMap.GasInsulation(), GasEnergyUsage = currentUsageEstimatorValueMap.GasEnergyUsage(), ElectricityHouseType = currentUsageEstimatorValueMap.ElectricityHouseTypeName(), ElectricityNumberOfBedrooms = currentUsageEstimatorValueMap.ElectricityNumberOfBedrooms(), ElectricityMainCookingSource = currentUsageEstimatorValueMap.ElectricityMainCookingSource(), ElectricityCookingFrequency = currentUsageEstimatorValueMap.ElectricityCookingFrequency(), ElectricityCentralHeating = currentUsageEstimatorValueMap.ElectricityCentralHeating(), ElectricityNumberOfOccupants = currentUsageEstimatorValueMap.ElectricityNumberOfOccupants(), ElectricityInsulation = currentUsageEstimatorValueMap.ElectricityInsulation(), ElectricityEnergyUsage = currentUsageEstimatorValueMap.ElectricityEnergyUsage(), GasCurrentSpend = switchResource.GetGasCurrentSpend(), ElectricityCurrentSpend = switchResource.GetElectricityCurrentSpend(), GasCurrentUsageAsKwh = switchResource.GetGasCurrentUsageAsKwh(), ElectricityCurrentUsageAsKwh = switchResource.GetElectricityCurrentUsageAsKwh(), TransferUrl = transferUri }; return(View(viewModel)); }
public async Task <IActionResult> Index(CurrentUsageViewModel viewModel) { var model = await _modelLoader.Load <Resource, CurrentUsageModel>(viewModel.CurrentUsageUri); model.Update(viewModel); var response = await _modelSaver.Save(model); if (response.Errors?.Any() ?? false) { return(View(await GetCurrentUsageViewModel(viewModel.CurrentUsageUri, response.Errors))); } return(RedirectToAction("Index", "Preferences", new { uri = response.GetNextUrl() })); }
public void SetUp() { var response = Substitute.For <IResponse>(); response.GetNextUrl().Returns("next-url"); _modelLoader = Substitute.For <ILoadModel>(); _modelSaver = Substitute.For <ISaveModel>(); _resource = new ResourceBuilder() .WithDataTemplate() .WithGroup("tariffFilterOptions") .WithItem("tariffFilterOption") .WithGroup("resultsOrder") .WithItem("resultsOrder") .WithGroup("limitToPaymentType") .WithItem("paymentMethod") .Build(); _viewModel = new PreferencesViewModel { PreferencesUri = _url, PaymentMethod = _paymentMethod, ResultsOrder = _resultOrders, TariffFilterOption = _tariffFilterOption }; _model = new PreferencesModel(_resource); _modelLoader.Load <Resource, PreferencesModel>(_viewModel.PreferencesUri).Returns(_model); _modelSaver.Save(_model).Returns(response); _sut = new PreferencesController(_modelLoader, _modelSaver); }
public async Task <IActionResult> Index(string uri) { var model = await _modelLoader.Load <FutureTariffDetail, FutureTariffDetailsModel>(uri); return(View(new FutureTariffDetailsViewModel { Supplies = model.GetSupplies() })); }
public async Task <IActionResult> Index(CurrentSupplyViewModel viewModel) { var model = await _modelLoader.Load <Resource, CurrentSupplyModel>(viewModel.CurrentSupplyUrl); model.Update(viewModel); var response = await _modelSaver.Save(model); if (response.Errors?.Any() ?? false) { return(View(await GetCurrentSupplyViewModel(viewModel.CurrentSupplyUrl, response.Errors))); } var switchResource = await _modelLoader.Load <SwitchResource, SwitchModel>(response.SwitchUrl); return(switchResource.IsProRata ? RedirectToAction("Index", "ContractExpiryDate", new { uri = switchResource.ContractExpiryDateUri }) : RedirectToAction("Index", "CurrentUsage", new { uri = response.GetNextUrl() })); }
public async Task <IActionResult> Index(ContractExpiryDateViewModel model) { var contractExpiry = await _modelLoader.Load <Resource, ContractExpiryDateModel>(model.ContractExpiryDateUri); contractExpiry.Update(model); var response = await _modelSaver.Save(contractExpiry); return(RedirectToAction("Index", "CurrentUsage", new { uri = response.GetNextUrl() })); }
public async Task <IActionResult> Index(StartSwitchViewModel viewModel) { var entry = await _modelLoader.Load <Resource, EntryModel>(_apiEntryPoint); var startSwitch = await _modelLoader.Load <Resource, StartSwitchModel>(entry.StartSwitchUrl); startSwitch.Update(viewModel.Postcode); var response = await _modelSaver.Save(startSwitch); if (response.Errors?.Any() ?? false) { return(View(new StartSwitchViewModel { Errors = response.Errors.Select(x => x.Message.Text) })); } var redirectController = response.ContainsRel("/rels/domestic/region") ? "Region" : "CurrentSupply"; return(RedirectToAction("Index", redirectController, new { uri = response.GetNextUrl() })); }
private void SetupStubbedSwitch(bool isProRata = false) { var switchResource = new SwitchResource { Links = new List <Link> { new Link { Rel = isProRata ? "/rels/domestic/contract-details" : "dummy-rel", Uri = isProRata ? "contract-expiry-date-uri" : "dummy-uri" }, new Link { Rel = "/rels/next", Uri = "next-uri" } } }; var switchModel = new SwitchModel(switchResource); _modelLoader.Load <SwitchResource, SwitchModel>("switch-uri").Returns(switchModel); }
public async Task <IActionResult> Index(PrepareForTransferViewModel viewModel) { var model = await _modelLoader.Load <Resource, PrepareForTransferModel>(viewModel.PrepareForTransferUri); model.Update(viewModel); var response = await _modelSaver.Save(model); if (response.Errors?.Any() ?? false) { return(View(GetPrepareForTransferViewModel(viewModel.PrepareForTransferUri, response.Errors))); } return(RedirectToAction("Index", "Switch", new { uri = response.SwitchUrl, transferUri = response.GetNextUrl() })); }
public void SetUp() { _resource = new ResourceBuilder() .WithDataTemplate() .WithGroup("gasContractDetails") .WithItem("expiryDate") .WithGroup("elecContractDetails") .WithItem("expiryDate") .Build(); _model = new ContractExpiryDateModel(_resource); _modelLoader = Substitute.For <ILoadModel>(); _modelSaver = Substitute.For <ISaveModel>(); _modelLoader.Load <Resource, ContractExpiryDateModel>(_uri).Returns(_model); _sut = new ContractExpiryDateController(_modelLoader, _modelSaver); }
public void SetUp() { _resource = new ResourceBuilder() .WithDataTemplate() .WithGroup("electricityRegion") .WithItem("region") .WithData("1") .Build(); _model = new RegionModel(_resource); _loader = Substitute.For <ILoadModel>(); _loader.Load <Resource, RegionModel>(_regionUri).Returns(_model); _saver = Substitute.For <ISaveModel>(); _controller = new RegionController(_loader, _saver); }
private void StubModelLoader() { _resource = _resourceBuilder.Build(); _model = new PrepareForTransferModel(_resource); _modelLoader.Load <Resource, PrepareForTransferModel>(_viewModel.PrepareForTransferUri).Returns(_model); }
public void SetUp() { _resource = new ResourceBuilder() .WithDataTemplate() .WithGroup("gasUsageType") .WithItem("usageType") .WithGroup("gasSimpleEstimate") .WithItem("simpleEstimate") .WithData("default-gas-simple-estimate") .WithGroup("elecUsageType") .WithItem("usageType") .WithGroup("elecSimpleEstimate") .WithItem("simpleEstimate") .WithData("default-electricity-simple-estimate") .WithGroup("gasDetailedEstimate") .WithItem("houseType") .WithItem("numberOfBedrooms") .WithItem("mainCookingSource") .WithItem("cookingFrequency") .WithItem("centralHeating") .WithItem("numberOfOccupants") .WithItem("insulation") .WithItem("energyUsage") .WithGroup("elecDetailedEstimate") .WithItem("houseType") .WithItem("numberOfBedrooms") .WithItem("mainCookingSource") .WithItem("cookingFrequency") .WithItem("centralHeating") .WithItem("numberOfOccupants") .WithItem("insulation") .WithItem("energyUsage") .WithGroup("gasSpend") .WithItem("usageAsSpend") .WithGroup("elecSpend") .WithItem("usageAsSpend") .WithGroup("gasKWhUsage") .WithItem("usageAsKWh") .WithGroup("elecKWhUsage") .WithItem("usageAsKWh") .WithGroup("economy7") .WithItem("nightUsagePercentage") .WithGroup("includedFuels") .WithItem("compareGas") .WithData("False") .WithItem("compareElec") .WithData("False") .Build(); var response = Substitute.For <IResponse>(); response.GetNextUrl().Returns("next-url"); _viewModel = new CurrentUsageViewModel { CurrentUsageUri = _uri, ElectricityUsageSimpleEstimator = "electrcicitySimpleEstimateValue", GasUsageSimpleEstimator = "gasSimpleEstimateValue", }; _modelLoader = Substitute.For <ILoadModel>(); _modelSaver = Substitute.For <ISaveModel>(); var model = new CurrentUsageModel(_resource); _modelLoader.Load <Resource, CurrentUsageModel>(_viewModel.CurrentUsageUri).Returns(model); _modelSaver.Save(model).Returns(response); _sut = new CurrentUsageController(_modelLoader, _modelSaver); }
private void StubFutureSupply() { _futureSupplyResource = _futureSupplyResourceBuilder.Build(); _futureSupplyModel = new FutureSupplyModel(_futureSupplyResource); _modelLoader.Load <Resource, FutureSupplyModel>(_uri).Returns(_futureSupplyModel); }