public void DeleteApplication(Guid candidateId, int vacancyId)
        {
            var applicationDetail = _apprenticeshipApplicationReadRepository.GetForCandidate(candidateId, vacancyId);

            if (applicationDetail != null)
            {
                applicationDetail.AssertState("Delete application", ApplicationStatuses.Draft, ApplicationStatuses.ExpiredOrWithdrawn);

                _apprenticeshipApplicationWriteRepository.Delete(applicationDetail.EntityId);
            }
        }
        private void DeleteApprenticeshipApplications(IList <ApprenticeshipApplicationSummary> apprenticeshipApplications)
        {
            if (apprenticeshipApplications != null)
            {
                foreach (var apprenticeshipApplicationSummary in apprenticeshipApplications)
                {
                    _logService.Info("Hard deleting Apprenticeship Application: {0}", apprenticeshipApplicationSummary.ApplicationId);

                    _apprenticeshipApplicationWriteRepository.Delete(apprenticeshipApplicationSummary.ApplicationId);

                    _logService.Info("Hard deleted Apprenticeship Application: {0}", apprenticeshipApplicationSummary.ApplicationId);
                }
            }
        }
        public ApprenticeshipApplicationDetail DeleteSavedVacancy(Guid candidateId, int vacancyId)
        {
            var applicationDetail = _apprenticeshipApplicationReadRepository.GetForCandidate(candidateId, vacancyId);

            if (applicationDetail == null)
            {
                return(null);
            }

            if (applicationDetail.Status != ApplicationStatuses.Saved)
            {
                return(applicationDetail);
            }

            // Only actually delete a saved vacancy.
            _apprenticeshipApplicationWriteRepository.Delete(applicationDetail.EntityId);
            _serviceBus.PublishMessage(new ApprenticeshipApplicationUpdate(applicationDetail.EntityId, ApplicationUpdateType.Delete));
            return(null);
        }
        public void Delete(VacancyType vacancyType, Guid applicationId)
        {
            _logService.Info("Deleting application: type={0}, id={1}", vacancyType, applicationId);

            switch (vacancyType)
            {
            case VacancyType.Apprenticeship:
                _apprenticeshipApplicationWriteRepository.Delete(applicationId);
                break;

            case VacancyType.Traineeship:
                _traineeshipApplicationWriteRepository.Delete(applicationId);
                break;

            default:
                throw new InvalidOperationException(string.Format("Unknown vacancy type: {0}.", vacancyType));
            }

            _logService.Info("Deleted application: type={0}, id={1}", vacancyType, applicationId);
        }