public async Task <ActionResult <ResultDto <IEnumerable <ApplicantDto> > > > GetAll() { try { return(ResultDto <IEnumerable <ApplicantDto> > .CreateSuccessfulResult( (await _applicantService.GetAllApplicants()).Select(ApplicantDto.FromApplicant))); } catch (Exception ex) { _logger.LogError(ex, "Error On get all applicants"); return(StatusCode(500, "Something went wrong on server side")); } }
public async Task <ActionResult <ApplicantDto> > Get([FromRoute] int id) { try { var applicant = await _applicantService.GetApplicant(id); if (applicant != null) { return(Ok(ResultDto <ApplicantDto> .CreateSuccessfulResult(ApplicantDto.FromApplicant(applicant)))); } return(NotFound()); } catch (Exception ex) { _logger.LogError(ex, "Error On get single applicant: id: {id}", id); return(StatusCode(500, "Something went wrong on server side")); } }
public async Task <IActionResult> Create([FromBody] CreateApplicantCommandDto applicantDto) { try { var result = await _applicantService.CreateApplicant(applicantDto.ToCreateApplicantCommand()); return(Created(Request.Path, ResultDto <int> .CreateSuccessfulResult(result))); } catch (DomainException ex) { var result = ResultDto <int> .CreateFailedResult( ex.InnerExceptions.Select(x => x.Message)); return(BadRequest(result)); } catch (Exception ex) { _logger.LogError(ex, "Error On creating new applicant: data: {@applicantDto}", applicantDto); return(StatusCode(500, "Something went wrong on server side")); } }