public async Task <PaginatedEntityResponseModel <RiskFactorResponse> > GetRiskFactorsAsync(int pageSize, int pageIndex) { IEnumerable <RiskFactor> riskFactorsFromDb = await _riskFactorRepository.GetAsync(pageSize, pageIndex); IEnumerable <RiskFactorResponse> riskFactorResponses = riskFactorsFromDb .Select(x => _riskFactorMapper.Map(x)); int totalRiskFactors = await _riskFactorRepository.CountRiskFactors(); return(new PaginatedEntityResponseModel <RiskFactorResponse> (pageIndex, pageSize, totalRiskFactors, riskFactorResponses)); }
public async Task <PatientResponse> AddPatientRiskFactor(AddPatientRiskFactorRequest request) { if ((request?.PatientId == null) || (request?.RiskFactorId == null)) { throw new ArgumentNullException(); } Patient patient = await _patientRepository.GetAsync(request.PatientId); RiskFactor riskFactor = await _riskFactorRepository.GetAsync(request.RiskFactorId); PatientRiskFactor patientRiskFactor = new PatientRiskFactor { //Přes Id to funguje, přes celé entity ne!!! PatientId = patient.Id, RiskFactorId = riskFactor.Id }; _patientRiskFactorRepository.Add(patientRiskFactor); await _patientRiskFactorRepository.UnitOfWork.SaveChangesAsync(); //aktualizace pacienta patient = await _patientRepository.GetAsync(request.PatientId); return(_patientMapper.Map(patient)); }