Example #1
0
        public async Task <ActionResult> SearchCompaniesHouse(SearchCompaniesHouseModel viewModel)
        {
            if (!viewModel.SearchText.IsNullOrEmpty())
            {
                if (viewModel.SearchText.IsInteger())
                {
                    viewModel.Results = await _companiesHouseService.SearchByCompaniesHouseNumber(viewModel.SearchText);
                }
                else
                {
                    viewModel.Results = await _companiesHouseService.SearchByName(viewModel.SearchText, viewModel.StartIndex, viewModel.PageSize);
                }
                viewModel.NotFound = !viewModel.Results.Items.Any();

                if (viewModel.Results.Count == 1)
                {
                    return(RedirectToAction("CreateAcademyTrust", "Group", new { companiesHouseNumber = viewModel.Results.Items.First().Number, area = "Groups" }));
                }
            }
            return(View(viewModel));
        }
Example #2
0
        public async Task <ActionResult> CreateAcademyTrust(string companiesHouseNumber)
        {
            if (string.IsNullOrWhiteSpace(companiesHouseNumber))
            {
                return(HttpNotFound());
            }

            var companyProfile = await _companiesHouseService.SearchByCompaniesHouseNumber(companiesHouseNumber);

            var groupTypes = await GetAcademyTrustGroupTypes();

            var vm = new CreateAcademyTrustViewModel(companyProfile.Items.First(), groupTypes);

            var existingTrust = await _groupReadService.SearchByIdsAsync(null, null, companiesHouseNumber, null, User);

            if (existingTrust != null && existingTrust.Items.Any())
            {
                vm.TrustExists = true;
                vm.TrustName   = existingTrust.Items.First().Name;
                vm.TypeId      = existingTrust.Items.First().GroupTypeId;
                vm.GroupId     = existingTrust.Items.First().GroupId;
                vm.GroupUid    = existingTrust.Items.First().GroupUId;
            }

            if (vm.Address == null)
            {
                ModelState.AddModelError("", "This company record doesn't have an address");
            }

            if (!vm.OpenDate.HasValue)
            {
                ModelState.AddModelError("", "This company record doesn't have an incorporation date");
            }

            vm.AllowSave = !vm.TrustExists && ModelState.IsValid;

            return(View(vm));
        }