public async Task <IActionResult> Index(Guid requestId) { var supportRequest = await _mediator.Send(new GetTempSupportRequest(requestId)); var vm = new OrganisationTypeViewModel(supportRequest); return(View("~/Views/RequestSupport/OrganisationType.cshtml", vm)); }
/// <summary> /// Convert OrganisationType Entity into OrganisationType Object /// </summary> ///<param name="model">OrganisationTypeViewModel</param> ///<param name="OrganisationTypeEntity">DataAccess.OrganisationType</param> ///<returns>OrganisationTypeViewModel</returns> public static OrganisationTypeViewModel ToViewModel( this DataAccess.OrganisationType entity, OrganisationTypeViewModel model) { model.Id = entity.Id; model.Name = entity.Name; model.IsActive = entity.IsActive; return(model); }
public void TypePost_Always_SetsInternalBreadcrumb() { var viewModel = new OrganisationTypeViewModel() { SearchedText = "Company", SelectedValue = "Partnership" }; controller.Type(viewModel); Assert.Equal("Add new organisation", breadcrumbService.InternalActivity); }
public void TypePost_ModelNotValid_ReturnsView() { var viewModel = new OrganisationTypeViewModel() { SearchedText = "Company" }; controller.ModelState.AddModelError("error", "error"); var result = controller.Type(viewModel) as ViewResult; var resultViewModel = result.Model as OrganisationTypeViewModel; Assert.True(string.IsNullOrEmpty(result.ViewName) || result.ViewName == "Type"); Assert.Equal(viewModel.SearchedText, resultViewModel.SearchedText); Assert.Equal(viewModel.PossibleValues, resultViewModel.PossibleValues); }
public void TypePost_ValidViewModel_ReturnsCorrectRedirect(string selectedValue, string action) { var viewModel = new OrganisationTypeViewModel() { SearchedText = "Company", SelectedValue = selectedValue, EntityType = fixture.Create <EntityType>() }; var result = controller.Type(viewModel) as RedirectToRouteResult; result.RouteValues["action"].Should().Be(action); result.RouteValues["controller"].Should().Be("AddOrganisation"); result.RouteValues["organisationType"].Should().Be(viewModel.SelectedValue); result.RouteValues["searchedText"].Should().Be(viewModel.SearchedText); result.RouteValues["entityType"].Should().Be(viewModel.EntityType); }
/// <summary> /// Convert OrganisationType Object into OrganisationType Entity /// </summary> ///<param name="model">OrganisationType</param> ///<param name="OrganisationTypeEntity">DataAccess.OrganisationType</param> ///<returns>DataAccess.OrganisationType</returns> public static DataAccess.OrganisationType ToEntity(this OrganisationTypeViewModel model, DataAccess.OrganisationType entity) { if (entity.Id == 0) { entity.CreatedUserId = model.SessionUserId; entity.IsActive = model.IsActive; } else { entity.UpdatedUserId = model.SessionUserId; entity.UpdatedTimestamp = DateTime.Now; } entity.Name = model.Name; return(entity); }
public async Task <IActionResult> Index(Guid requestId, OrganisationTypeViewModel viewModel) { if (!ModelState.IsValid) { return(View("~/Views/RequestSupport/OrganisationType.cshtml", viewModel)); } if (viewModel.SelectedOrganisationType == OrganisationType.Other && string.IsNullOrWhiteSpace(viewModel.Other)) { ModelState.AddModelError("Other", "Please enter something for other"); return(View("~/Views/RequestSupport/OrganisationType.cshtml", viewModel)); } var supportRequest = await _mediator.Send(new GetTempSupportRequest(requestId)); viewModel.UpdateTempSupportRequest(supportRequest); await _mediator.Send(new SaveTempSupportRequest()); return(RedirectToAction("Index", "OrganisationSearch", new { requestId = requestId })); }
public ActionResult Index([DefaultValue(1)] int page, string keywords, [DefaultValue(12)] int pgsize) { try { List <sw.OrganisationType> rowsToShow = new List <sw.OrganisationType>(); int totalRecords = 0; if (!string.IsNullOrEmpty(keywords)) { rowsToShow = swdb.OrganisationType.Where(x => x.Name.ToUpper().Contains(keywords.Trim().ToUpper())).OrderBy(x => x.Id).Skip((page - 1) * pgsize).Take(pgsize).ToList(); totalRecords = swdb.OrganisationType.Count(x => x.Name.ToUpper().Contains(keywords.Trim().ToUpper())); } else { rowsToShow = swdb.OrganisationType.OrderBy(x => x.Id).Skip((page - 1) * pgsize).Take(pgsize).ToList(); totalRecords = swdb.OrganisationType.Count(); } OrganisationTypeViewModel model = new OrganisationTypeViewModel() { Rows = rowsToShow, PagingInfo = new PagingInfo { FirstItem = ((page - 1) * pgsize) + 1, LastItem = page * pgsize, CurrentPage = page, ItemsPerPage = pgsize, TotalItems = totalRecords }, CurrentKeywords = keywords, PageSize = pgsize }; return(View(model)); } catch (Exception ex) { // Log with Elmah TempData["message"] = Settings.Default.GenericExceptionMessage; return(RedirectToAction("Index", "Home", new { area = "Admin" })); } }
public ActionResult Type(OrganisationTypeViewModel model) { SetBreadcrumb(InternalUserActivity.CreateOrganisation); if (ModelState.IsValid) { var organisationType = model.SelectedValue.GetValueFromDisplayName <OrganisationType>(); var routeValues = new { organisationType = model.SelectedValue, entityType = model.EntityType, searchedText = model.SearchedText }; switch (organisationType) { case OrganisationType.SoleTraderOrIndividual: return(RedirectToAction(nameof(SoleTraderDetails), "AddOrganisation", routeValues)); case OrganisationType.Partnership: return(RedirectToAction(nameof(PartnershipDetails), "AddOrganisation", routeValues)); case OrganisationType.RegisteredCompany: return(RedirectToAction(nameof(RegisteredCompanyDetails), "AddOrganisation", routeValues)); } } return(View(model)); }
public async Task PostType_TypeDetailsSelectionWithOrganisationId_RedirectsToCorrectControllerAction(OrganisationType type, string action) { // Arrange OrganisationData orgData = new OrganisationData { OrganisationType = type, Id = Guid.NewGuid() }; IWeeeClient weeeClient = A.Fake<IWeeeClient>(); A.CallTo(() => weeeClient.SendAsync(A<string>._, A<VerifyOrganisationExistsAndIncomplete>._)) .Returns(true); A.CallTo(() => weeeClient.SendAsync(A<string>._, A<GetOrganisationInfo>._)) .Returns(orgData); ISearcher<OrganisationSearchResult> organisationSearcher = A.Dummy<ISearcher<OrganisationSearchResult>>(); OrganisationRegistrationController controller = new OrganisationRegistrationController( () => weeeClient, organisationSearcher); OrganisationTypeViewModel model = new OrganisationTypeViewModel( type, new Guid("35EFE82E-0706-4E80-8AFA-D81C4B58102A")); // Act ActionResult result = await controller.Type(model); // Assert var redirectToRouteResult = ((RedirectToRouteResult)result); Assert.Equal(action, redirectToRouteResult.RouteValues["action"]); }
public async Task PostType_TypeDetailsSelectionWithoutOrganisationId_RedirectsToCorrectControllerAction(string selection, string action) { // Arrange IWeeeClient weeeClient = A.Dummy<IWeeeClient>(); ISearcher<OrganisationSearchResult> organisationSearcher = A.Dummy<ISearcher<OrganisationSearchResult>>(); OrganisationRegistrationController controller = new OrganisationRegistrationController( () => weeeClient, organisationSearcher); OrganisationTypeViewModel model = new OrganisationTypeViewModel(); model.SelectedValue = selection; model.OrganisationId = null; // Act ActionResult result = await controller.Type(model); // Assert var redirectToRouteResult = ((RedirectToRouteResult)result); Assert.Equal(action, redirectToRouteResult.RouteValues["action"]); }
public async Task<ActionResult> Type(OrganisationTypeViewModel model) { if (ModelState.IsValid) { var organisationType = model.SelectedValue.GetValueFromDisplayName<OrganisationType>(); if (model.OrganisationId != null) { using (var client = apiClient()) { await GetOrganisation(model.OrganisationId.Value, client); switch (organisationType) { case OrganisationType.SoleTraderOrIndividual: return RedirectToAction("SoleTraderDetails", new { organisationId = model.OrganisationId.Value }); case OrganisationType.RegisteredCompany: return RedirectToAction("RegisteredCompanyDetails", new { organisationId = model.OrganisationId.Value }); case OrganisationType.Partnership: return RedirectToAction("PartnershipDetails", new { organisationId = model.OrganisationId.Value }); } } } else { switch (organisationType) { case OrganisationType.SoleTraderOrIndividual: return RedirectToAction("SoleTraderDetails", new { searchedText = model.SearchedText }); case OrganisationType.RegisteredCompany: return RedirectToAction("RegisteredCompanyDetails", new { searchedText = model.SearchedText }); case OrganisationType.Partnership: return RedirectToAction("PartnershipDetails", new { searchedText = model.SearchedText }); } } } return View(model); }
public async Task<ActionResult> Type(string searchedText, Guid? organisationId = null) { if (organisationId != null) { using (var client = apiClient()) { var organisation = await GetOrganisation(organisationId, client); var model = new OrganisationTypeViewModel(organisationId.Value); return View("Type", model); } } return View(new OrganisationTypeViewModel(searchedText)); }