Example #1
0
        public async Task <ExamReport> SaveAsync <V>(int userId, ExamReport examReport) where V : AbstractValidator <ExamReport>
        {
            var medic = await _medicService.FindByIdAsync(userId);

            if (!(medic is Medic))
            {
                throw new Exception("Usuario não é um médico");
            }

            var examRequest = await _examRequestService.FindByIdAsync(examReport.ExamRequestId);

            if (examRequest == null)
            {
                throw new Exception("Pedido de exame não existe");
            }

            var newExamReport = new ExamReport
            {
                Medic       = medic,
                ExamRequest = examRequest,
                Description = examReport.Description,
                Cid         = examReport.Cid,
                Status      = ExamReportStatus.ANDAMENTO
            };
            var report = await _examReportRepository.SaveAsync(newExamReport);

            await _unitOfWork.CompleteAsync();

            return(report);
        }