Exemple #1
0
        public async Task <IActionResult> Delete(DeletePatientRiskFactorRequest request)
        {
            //return Ok(await _patientRiskFactorService.DeletePatientRiskFactor(request));
            await _patientRiskFactorService.DeletePatientRiskFactor(request);

            return(NoContent());
        }
Exemple #2
0
        public async Task <PatientResponse> EditPatientAsync(EditPatientRequest request)
        {
            var existingRecord = await _patientRepository.GetAsync(request.Id);

            if (existingRecord == null)
            {
                throw new ArgumentException($"Entity with {request.Id} does not exist!");
            }

            var entity = _patientMapper.Map(request);
            var result = _patientRepository.Update(entity);

            // Delete old records in joining table for existing record:
            if (existingRecord.PatientRiskFactors != null)
            {
                foreach (PatientRiskFactor patientRiskFactor in existingRecord.PatientRiskFactors)
                {
                    DeletePatientRiskFactorRequest deletePRF = new DeletePatientRiskFactorRequest
                    {
                        PatientId    = patientRiskFactor.PatientId,
                        RiskFactorId = patientRiskFactor.RiskFactorId
                    };
                    await _patientRiskFactorService.DeletePatientRiskFactor(deletePRF);
                }
            }


            // Create new records in joining table:
            if (request.RiskFactors != null)
            {
                foreach (GetRiskFactorRequest riskFactor in request.RiskFactors)
                {
                    AddPatientRiskFactorRequest addPRFRequest = new AddPatientRiskFactorRequest
                    {
                        PatientId    = request.Id,
                        RiskFactorId = riskFactor.Id
                    };
                    await _patientRiskFactorService.AddPatientRiskFactor(addPRFRequest);
                }
            }

            // Confirm changes:
            await _patientRepository.UnitOfWork.SaveChangesAsync();

            return(_patientMapper.Map(result));
        }