示例#1
0
        public async Task <ActionResult <CaseReportResource> > CreateCaseReport([FromBody] SaveCaseReportResource saveCaseReportResource)
        {
            var validator        = new SaveCaseReportResourceValidator();
            var validationResult = await validator.ValidateAsync(saveCaseReportResource);

            if (!validationResult.IsValid)
            {
                return(BadRequest(validationResult.Errors));
            }

            var caseReportToCreate = _mapper.Map <SaveCaseReportResource, CaseReport>(saveCaseReportResource);
            var newCaseReport      = await _caseReportService.CreateCaseReport(caseReportToCreate);

            var caseReportResource = _mapper.Map <CaseReport, CaseReportResource>(newCaseReport);

            return(Ok(caseReportResource));
        }
示例#2
0
        public async Task <ActionResult <CaseReportResource> > UpdateCaseReport(int id, [FromBody] SaveCaseReportResource saveCaseReportResource)
        {
            var validator        = new SaveCaseReportResourceValidator();
            var validationResult = await validator.ValidateAsync(saveCaseReportResource);

            var requestIsInvalid = id == 0 || !validationResult.IsValid;

            if (requestIsInvalid)
            {
                return(BadRequest(validationResult.Errors));
            }

            var caseReport = _mapper.Map <SaveCaseReportResource, CaseReport>(saveCaseReportResource);

            await _caseReportService.UpdateCaseReport(id, caseReport);

            var updatedCaseReport = await _caseReportService.GetCaseReportById(id);

            var updatedCaseReportResource = _mapper.Map <CaseReport, CaseReportResource>(updatedCaseReport);

            return(Ok(updatedCaseReportResource));
        }