public void PostChooseActivity_WithInvalidModel_ReturnsChooseActivityViewWithViewModelAndAddsAuthorityToViewBag() { // Arrange ChargeController controller = new ChargeController( A.Dummy <IAppConfiguration>(), A.Dummy <BreadcrumbService>(), () => A.Dummy <IWeeeClient>()); controller.ModelState.AddModelError("key", "Some error"); // Act ActionResult result = controller.ChooseActivity(CompetentAuthority.NorthernIreland, A.Dummy <ChooseActivityViewModel>()); // Assert ViewResult viewResult = result as ViewResult; Assert.NotNull(viewResult); Assert.True(viewResult.ViewName == string.Empty || viewResult.ViewName == "ChooseActivity"); ChooseActivityViewModel viewModel = viewResult.Model as ChooseActivityViewModel; Assert.NotNull(viewModel); Assert.Equal(CompetentAuthority.NorthernIreland, (object)viewResult.ViewBag.Authority); }
public async Task <ActionResult> ChooseActivity(Guid pcsId) { using (var client = apiClient()) { var organisationExists = await client.SendAsync(User.GetAccessToken(), new VerifyOrganisationExists(pcsId)); if (!organisationExists) { throw new ArgumentException("No organisation found for supplied organisation Id", "organisationId"); } var activities = await GetActivities(pcsId); var model = new ChooseActivityViewModel(activities) { OrganisationId = pcsId }; await SetBreadcrumb(pcsId, null, false); await SetShowLinkToCreateOrJoinOrganisation(model); return(View(model)); } }
public IActionResult Index() { List <ChooseActivityViewModel> chooseActivites = new List <ChooseActivityViewModel>(); List <RecretionalActivity> allActivities = new List <RecretionalActivity>(); var allUserActivities = _userActivityService.GetAllUserActivities(); var user = _userManager.GetUserAsync(User).Result; allActivities = _activityService.GetAllActivities().ToList(); allActivities.ForEach(x => { var userActivity = _userActivityService.GetUserActivityById(user.Id, x.ActivityId); ChooseActivityViewModel chooseActivity = null; if (userActivity != null) { chooseActivity = new ChooseActivityViewModel { Activity = x, IsChoosen = x.ActivityId == userActivity.ActivityId } } ; else { chooseActivity = new ChooseActivityViewModel { Activity = x } }; chooseActivites.Add(chooseActivity); }); return(View(chooseActivites)); }
private async Task SetShowLinkToCreateOrJoinOrganisation(ChooseActivityViewModel model) { var organisations = await GetOrganisations(); var accessibleOrganisations = organisations .Where(o => o.UserStatus == UserStatus.Active) .ToList(); var inaccessibleOrganisations = organisations .Except(accessibleOrganisations) .ToList(); var showLink = (accessibleOrganisations.Count == 1 && inaccessibleOrganisations.Count == 0); model.ShowLinkToCreateOrJoinOrganisation = showLink; }
public ActionResult ChooseActivity(CompetentAuthority authority, ChooseActivityViewModel viewModel) { if (!ModelState.IsValid) { ViewBag.Authority = authority; return(View(viewModel)); } switch (viewModel.SelectedActivity.Value) { case Activity.ManagePendingCharges: return(RedirectToAction("ManagePendingCharges", new { authority })); case Activity.ManageIssuedCharges: return(RedirectToAction("IssuedCharges", new { authority })); case Activity.ViewInvoiceRunHistory: return(RedirectToAction("InvoiceRuns", new { authority })); default: throw new NotSupportedException(); } }
public ActionResult ChooseActivity(CompetentAuthority authority, ChooseActivityViewModel viewModel) { if (!ModelState.IsValid) { ViewBag.Authority = authority; return View(viewModel); } switch (viewModel.SelectedActivity.Value) { case Activity.ManagePendingCharges: return RedirectToAction("ManagePendingCharges", new { authority }); case Activity.ManageIssuedCharges: return RedirectToAction("IssuedCharges", new { authority }); case Activity.ViewInvoiceRunHistory: return RedirectToAction("InvoiceRuns", new { authority }); default: throw new NotSupportedException(); } }
public async Task<ActionResult> ChooseActivity(Guid pcsId) { using (var client = apiClient()) { var organisationExists = await client.SendAsync(User.GetAccessToken(), new VerifyOrganisationExists(pcsId)); if (!organisationExists) { throw new ArgumentException("No organisation found for supplied organisation Id", "organisationId"); } List<string> activities = await GetActivities(pcsId); var model = new ChooseActivityViewModel(activities); model.OrganisationId = pcsId; await SetBreadcrumb(pcsId, null); await SetShowLinkToCreateOrJoinOrganisation(model); return View(model); } }
public void PostChooseActivity_WithViewInvoiceRunHistorySelected_RedirectsToInvoiceRunsActionWithSelectedAuthority() { // Arrange ChargeController controller = new ChargeController( A.Dummy <IAppConfiguration>(), A.Dummy <BreadcrumbService>(), () => A.Dummy <IWeeeClient>()); ChooseActivityViewModel viewModel = new ChooseActivityViewModel(); viewModel.SelectedActivity = Activity.ViewInvoiceRunHistory; // Act ActionResult result = controller.ChooseActivity(CompetentAuthority.NorthernIreland, viewModel); // Assert RedirectToRouteResult redirectResult = result as RedirectToRouteResult; Assert.NotNull(redirectResult); Assert.Equal("InvoiceRuns", redirectResult.RouteValues["action"]); Assert.Equal(CompetentAuthority.NorthernIreland, redirectResult.RouteValues["authority"]); }
private async Task SetShowLinkToCreateOrJoinOrganisation(ChooseActivityViewModel model) { IEnumerable<OrganisationUserData> organisations = await GetOrganisations(); List<OrganisationUserData> accessibleOrganisations = organisations .Where(o => o.UserStatus == UserStatus.Active) .ToList(); List<OrganisationUserData> inaccessibleOrganisations = organisations .Except(accessibleOrganisations) .ToList(); bool showLink = (accessibleOrganisations.Count == 1 && inaccessibleOrganisations.Count == 0); model.ShowLinkToCreateOrJoinOrganisation = showLink; }
public async Task<ActionResult> ChooseActivity(ChooseActivityViewModel viewModel) { if (ModelState.IsValid) { if (viewModel.SelectedValue == PcsAction.ManagePcsMembers) { using (var client = apiClient()) { var status = await client.SendAsync(User.GetAccessToken(), new GetSchemeStatus(viewModel.OrganisationId)); if (status == SchemeStatus.Approved) { return RedirectToAction("Summary", "MemberRegistration", new { pcsId = viewModel.OrganisationId }); } else { return RedirectToAction("AuthorisationRequired", "MemberRegistration", new { pcsId = viewModel.OrganisationId }); } } } if (viewModel.SelectedValue == PcsAction.ManageOrganisationUsers) { return RedirectToAction("ManageOrganisationUsers", new { pcsId = viewModel.OrganisationId }); } if (viewModel.SelectedValue == PcsAction.ViewRegisteredOfficeDetails || viewModel.SelectedValue == PcsAction.ViewPrinciplePlaceOfBusinessDetails) { return RedirectToAction("ViewOrganisationDetails", new { pcsId = viewModel.OrganisationId }); } if (viewModel.SelectedValue == PcsAction.ManageContactDetails) { return RedirectToAction("ManageContactDetails", new { pcsId = viewModel.OrganisationId }); } if (viewModel.SelectedValue == PcsAction.ViewSubmissionHistory) { var organisationOverview = await GetOrganisationOverview(viewModel.OrganisationId); bool canViewDataReturnsSubmission = organisationOverview.HasDataReturnSubmissions && configurationService.CurrentConfiguration.EnableDataReturns; if (organisationOverview.HasMemberSubmissions && canViewDataReturnsSubmission) { return RedirectToAction("ChooseSubmissionType", new { pcsId = viewModel.OrganisationId }); } else if (organisationOverview.HasMemberSubmissions) { return RedirectToAction("ViewSubmissionHistory", new { pcsId = viewModel.OrganisationId }); } else if (canViewDataReturnsSubmission) { return RedirectToAction("ViewDataReturnSubmissionHistory", new { pcsId = viewModel.OrganisationId }); } } if (viewModel.SelectedValue == PcsAction.ManageEeeWeeeData) { return RedirectToAction("Index", "DataReturns", new { pcsId = viewModel.OrganisationId }); } } await SetBreadcrumb(viewModel.OrganisationId, null); viewModel.PossibleValues = await GetActivities(viewModel.OrganisationId); await SetShowLinkToCreateOrJoinOrganisation(viewModel); return View(viewModel); }
public async Task <ActionResult> ChooseActivity(ChooseActivityViewModel viewModel) { if (ModelState.IsValid) { if (viewModel.SelectedValue == PcsAction.ManagePcsMembers) { using (var client = apiClient()) { var status = await client.SendAsync(User.GetAccessToken(), new GetSchemeStatus(viewModel.OrganisationId)); if (status == SchemeStatus.Approved) { return(RedirectToAction("Summary", "MemberRegistration", new { pcsId = viewModel.OrganisationId })); } else { return(RedirectToAction("AuthorisationRequired", "MemberRegistration", new { pcsId = viewModel.OrganisationId })); } } } if (viewModel.SelectedValue == PcsAction.ManageOrganisationUsers) { return(RedirectToAction("ManageOrganisationUsers", new { pcsId = viewModel.OrganisationId })); } if (viewModel.SelectedValue == PcsAction.ViewOrganisationDetails) { return(RedirectToAction("ViewOrganisationDetails", new { pcsId = viewModel.OrganisationId })); } if (viewModel.SelectedValue == PcsAction.ManageContactDetails) { return(RedirectToAction("ManageContactDetails", new { pcsId = viewModel.OrganisationId })); } if (viewModel.SelectedValue == PcsAction.ViewSubmissionHistory) { var organisationOverview = await GetOrganisationOverview(viewModel.OrganisationId); var canViewDataReturnsSubmission = organisationOverview.HasDataReturnSubmissions && configurationService.CurrentConfiguration.EnableDataReturns; if (organisationOverview.HasMemberSubmissions && canViewDataReturnsSubmission) { return(RedirectToAction("ChooseSubmissionType", new { pcsId = viewModel.OrganisationId })); } else if (organisationOverview.HasMemberSubmissions) { return(RedirectToAction("ViewSubmissionHistory", new { pcsId = viewModel.OrganisationId })); } else if (canViewDataReturnsSubmission) { return(RedirectToAction("ViewDataReturnSubmissionHistory", new { pcsId = viewModel.OrganisationId })); } } if (viewModel.SelectedValue == PcsAction.ManageEeeWeeeData) { return(RedirectToAction("Index", "DataReturns", new { pcsId = viewModel.OrganisationId })); } if (viewModel.SelectedValue == PcsAction.ManageAatfReturns) { return(AatfRedirect.ReturnsList(viewModel.OrganisationId)); } if (viewModel.SelectedValue == PcsAction.ManageAeReturns) { return(AeRedirect.ReturnsList(viewModel.OrganisationId)); } if (viewModel.SelectedValue == PcsAction.ManageAatfContactDetails) { return(this.RedirectToAction("Index", "Home", new { area = "Aatf", organisationId = viewModel.OrganisationId, FacilityType = FacilityType.Aatf })); } if (viewModel.SelectedValue == PcsAction.ManageAeContactDetails) { return(this.RedirectToAction("Index", "Home", new { area = "Aatf", organisationId = viewModel.OrganisationId, FacilityType = FacilityType.Ae })); } } await SetBreadcrumb(viewModel.OrganisationId, null, false); viewModel.PossibleValues = await GetActivities(viewModel.OrganisationId); await this.SetShowLinkToCreateOrJoinOrganisation(viewModel); return(this.View(viewModel)); }
public void PostChooseActivity_WithViewInvoiceRunHistorySelected_RedirectsToInvoiceRunsActionWithSelectedAuthority() { // Arrange ChargeController controller = new ChargeController( A.Dummy<IAppConfiguration>(), A.Dummy<BreadcrumbService>(), () => A.Dummy<IWeeeClient>()); ChooseActivityViewModel viewModel = new ChooseActivityViewModel(); viewModel.SelectedActivity = Activity.ViewInvoiceRunHistory; // Act ActionResult result = controller.ChooseActivity(CompetentAuthority.NorthernIreland, viewModel); // Assert RedirectToRouteResult redirectResult = result as RedirectToRouteResult; Assert.NotNull(redirectResult); Assert.Equal("InvoiceRuns", redirectResult.RouteValues["action"]); Assert.Equal(CompetentAuthority.NorthernIreland, redirectResult.RouteValues["authority"]); }