示例#1
0
        public OperationResult <bool> Delete(int id)
        {
            // Whether we have linked records
            var interviewRecordsExists = _interviewRoundRepository.Any(a => a.CandidateId == id);

            if (interviewRecordsExists)
            {
                return(new OperationResult <bool> {
                    Status = false, Message = "We cannot delete Candidate as we have interviews records"
                });
            }

            var jobOfferExists = _jobOfferRepository.Any(a => a.CandidateId == id);

            if (jobOfferExists)
            {
                return(new OperationResult <bool> {
                    Status = false, Message = "We cannot delete Candidate as we have Job Offer for him"
                });
            }

            // Delete all Candidate Activities
            var activities = _candidateActivityRepository.GetAllBy(m => m.CandidateId == id).ToList();

            foreach (var activity in activities)
            {
                _candidateActivityRepository.Delete(activity);
            }

            // Delete all Candidate Documents
            var docs = _candidateDocumentRepository.GetAllBy(m => m.CandidateId == id).ToList();

            foreach (var doc in docs)
            {
                _candidateDocumentRepository.Delete(doc);
            }

            // Delete all Candidate Technology Mappings
            var mappings = _candidateTechnologyMapRepository.GetAllBy(m => m.CandidateId == id).ToList();

            foreach (var mapping in mappings)
            {
                _candidateTechnologyMapRepository.Delete(mapping);
            }

            _candidateRepository.Delete(id);
            _unitOfWork.Commit();

            return(new OperationResult <bool> {
                Status = true
            });
        }
 public ActionResult DeleteConfirmed(int id)
 {
     _candidateDocumentRepository.Delete(id);
     _unitOfWork.Commit();
     return(RedirectToAction("Index"));
 }