Example #1
0
        public async Task <OrchestratorResponse <VacancyInfo> > CloseVacancyAsync(CloseEditModel m, VacancyUser user)
        {
            var vacancy = await _vacancyClient.GetVacancyAsync(m.VacancyId.GetValueOrDefault());

            Utility.CheckAuthorisedAccess(vacancy, m.Ukprn);

            if (!vacancy.CanClose)
            {
                throw new InvalidStateException(string.Format(ErrorMessages.VacancyNotAvailableForClosing, vacancy.Title));
            }

            await _vacancyClient.CloseVacancyAsync(vacancy.Id, user, ClosureReason.Manual);

            return(new OrchestratorResponse <VacancyInfo>(new VacancyInfo {
                Id = vacancy.Id,
                VacancyReference = vacancy.VacancyReference.Value.ToString(),
                Title = vacancy.Title
            }));
        }
        public async Task <IActionResult> Close(CloseEditModel m)
        {
            if (!ModelState.IsValid)
            {
                var vrm = new VacancyRouteModel {
                    VacancyId = m.VacancyId, EmployerAccountId = m.EmployerAccountId
                };
                return(await GetCloseVacancyConfirmationView(vrm));
            }

            if (!m.ConfirmClose.Value)
            {
                return(RedirectToRoute(RouteNames.VacancyManage_Get));
            }

            var response = await _orchestrator.CloseVacancyAsync(m, User.ToVacancyUser());

            TempData.Add(TempDataKeys.VacancyClosedMessage, string.Format(InfoMessages.VacancyClosed, response.Data.VacancyReference, response.Data.Title));

            return(RedirectToRoute(RouteNames.VacancyManage_Get));
        }