public async Task <OrchestratorResponse <SearchOrganisationResultsViewModel> > SearchOrganisation(string searchTerm, int pageNumber, OrganisationType?organisationType, string hashedAccountId, string userId) { var response = new OrchestratorResponse <SearchOrganisationResultsViewModel>(); try { _cookieService.Delete(CookieName); var result = await Mediator.SendAsync(new GetOrganisationsRequest { SearchTerm = searchTerm, PageNumber = pageNumber, OrganisationType = organisationType }); response.Data = new SearchOrganisationResultsViewModel { Results = CreateResult(result.Organisations), SearchTerm = searchTerm, OrganisationType = organisationType }; if (!string.IsNullOrEmpty(hashedAccountId)) { await SetAlreadySelectedOrganisations(hashedAccountId, userId, response.Data.Results); } } catch (InvalidRequestException ex) { response.Exception = ex; response.FlashMessage = FlashMessageViewModel.CreateErrorFlashMessageViewModel(ex.ErrorMessages); response.Status = HttpStatusCode.BadRequest; } return(response); }
private static void SetSearchTermValidationModelProperties(OrchestratorResponse model) { model.Status = HttpStatusCode.BadRequest; model.FlashMessage = FlashMessageViewModel.CreateErrorFlashMessageViewModel(new Dictionary <string, string> { { "searchTerm", "Enter organisation name" } }); }
public virtual async Task <OrchestratorResponse <bool> > RemoveLegalAgreement(ConfirmLegalAgreementToRemoveViewModel model, string userId) { var response = new OrchestratorResponse <bool>(); try { if (model.RemoveOrganisation == null) { response.Status = HttpStatusCode.BadRequest; response.FlashMessage = FlashMessageViewModel.CreateErrorFlashMessageViewModel(new Dictionary <string, string> { { "RemoveOrganisation", "Confirm you wish to remove the organisation" } }); return(response); } if (model.RemoveOrganisation == 1) { response.Status = HttpStatusCode.Continue; return(response); } await _mediator.SendAsync(new RemoveLegalEntityCommand { HashedAccountId = model.HashedAccountId, UserId = userId, HashedLegalAgreementId = model.HashedAgreementId }); response.FlashMessage = new FlashMessageViewModel { Headline = $"You have removed {model.Name}.", Severity = FlashMessageSeverityLevel.Success }; response.Data = true; } catch (InvalidRequestException ex) { response.Status = HttpStatusCode.BadRequest; response.FlashMessage = FlashMessageViewModel.CreateErrorFlashMessageViewModel(ex.ErrorMessages); response.Exception = ex; } catch (UnauthorizedAccessException ex) { response.Status = HttpStatusCode.Unauthorized; response.Exception = ex; } return(response); }
public virtual async Task <OrchestratorResponse <ConfirmOrganisationToRemoveViewModel> > RemoveLegalAgreement(ConfirmOrganisationToRemoveViewModel model, string userId) { var response = new OrchestratorResponse <ConfirmOrganisationToRemoveViewModel>(); try { await _mediator.SendAsync(new RemoveLegalEntityCommand { HashedAccountId = model.HashedAccountId, UserId = userId, HashedAccountLegalEntityId = model.HashedAccountLegalEntitytId }); response.FlashMessage = new FlashMessageViewModel { Headline = $"You have removed {model.Name}.", Severity = FlashMessageSeverityLevel.Success }; response.Status = HttpStatusCode.OK; response.Data = model; } catch (InvalidRequestException ex) { response.Status = HttpStatusCode.BadRequest; response.FlashMessage = FlashMessageViewModel.CreateErrorFlashMessageViewModel(ex.ErrorMessages); response.Exception = ex; } catch (UnauthorizedAccessException ex) { response.Status = HttpStatusCode.Unauthorized; response.Exception = ex; } return(response); }