Exemplo n.º 1
0
        public ActionResult <CandidateDTO> PostCandidate(CandidateDTO candidate)
        {
            log.LogInformation("Create candidate");

            try
            {
                candidateRepository.Add(candidate.ToEntity());

                log.LogInformation("Create successfully - new CandidateId: " + candidate.CandidateId);
            }
            catch (System.Exception ex)
            {
                log.LogError("Error creating candidate: " + ex.Message ?? ex.InnerException.Message);
            }

            return(CreatedAtAction("GetCandidate", new { id = candidate.CandidateId }, candidate));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> PutCandidateAsync(CandidateDTO candidate)
        {
            log.LogInformation("Update candidate - CandidateId: " + candidate.CandidateId);

            try
            {
                candidateRepository.RemovePreviousJobsById(candidate.CandidateId);

                var candidateUpdated = await candidateRepository.GetByIdAsync(candidate.CandidateId);

                candidate.ToEntity(candidateUpdated);

                candidateRepository.Update(candidateUpdated);
            }
            catch (DbUpdateConcurrencyException ex)
            {
                log.LogError("Database update error: " + ex.Message ?? ex.InnerException.Message);
            }

            log.LogWarning("Updated candidate successfully - CandidateId: " + candidate.CandidateId);

            return(NoContent());
        }