public IResult AddCandidate(CandidateViewModel candidateViewModel, CandidateDocumentViewModel candidateDocumentViewModel) { var result = new Result { Operation = Operation.Create, Status = Status.Success }; try { var candidateModel = new Candidates(); candidateModel.MapFromViewModel(candidateViewModel, (ClaimsIdentity)_principal.Identity); candidateModel.QualificationId = candidateViewModel.Qualification; #region Insert OpeningCandidate var openingCandidate = new OpeningCandidates(); openingCandidate.OpeningId = candidateViewModel.OpeningId; openingCandidate.Candidate = candidateModel; openingCandidate.MapAuditColumns((ClaimsIdentity)_principal.Identity); #endregion #region Insert Organization Organizations organization = null; if (candidateViewModel.OrganizationId != 0) { candidateModel.OrganizationId = candidateViewModel.OrganizationId; } else { organization = new Organizations { Name = candidateViewModel.OrganizationName }; organization.MapAuditColumns((ClaimsIdentity)_principal.Identity); candidateModel.Organisation = organization; } #endregion #region Insert Candidate Document var candidateDocumentModel = new CandidateDocuments(); candidateDocumentModel.MapFromViewModel(candidateDocumentViewModel, (ClaimsIdentity)_principal.Identity); candidateModel.CandidateDocuments.Add(candidateDocumentModel); #endregion _candidateRepository.AddCandidate(candidateModel, openingCandidate); result.Body = candidateModel.CandidateId; } catch (Exception e) { result.Message = e.Message; result.Status = Status.Error; } return(result); }
public void UpdateCandidate(Candidates candidate, OpeningCandidates openingCandidate) { if (openingCandidate.Opening != null) { _context.Entry(openingCandidate).State = EntityState.Modified; } var candidateDocument = candidate.CandidateDocuments.FirstOrDefault(); if (candidateDocument.CandidateDocumentId != Guid.Empty) { _context.Entry(candidateDocument).State = EntityState.Modified; } _context.Entry(candidate).State = EntityState.Modified; _context.SaveChanges(); }
public void AddCandidate(Candidates candidate, OpeningCandidates openingCandidate) { _context.Candidates.Add(candidate); _context.OpeningCandidates.Add(openingCandidate); _context.SaveChanges(); }