public ResultOfType <PatientResultModel> GetPatients(int take = 0, int skip = 0) { try { Logger.LogInfo("Get Patients With Take And Skip Parameters : Start."); var totalCount = _patientRepository.GetCount(); var totalPages = (take != 0) ? (int)Math.Ceiling((double)totalCount / take) : 0; var paginationHeader = new PaginationHeader { TotalCount = totalCount, TotalPages = totalPages }; var patients = (take == 0 && skip == 0) ? _patientRepository .GetAll() .OrderBy(a => a.CreationDate) .ToList() : _patientRepository .GetAll() .OrderBy(a => a.CreationDate) .Skip(skip) .Take(take) .ToList(); var data = new PatientResultModel(); patients.ForEach(patient => { var dataModel = PatientWrapper.ConvertPatientEntityToDataModel(patient); data.Items.Add(dataModel); }); data.PaginationHeader = paginationHeader; Logger.LogInfo("Get Patients With Take And Skip Parameters : End --- Status : OK"); return(new Return <PatientResultModel>().OK().WithResult(data)); } catch (Exception exception) { Logger.LogError("Get Patients Exception", exception); throw; } }
public ResultOfType <PatientResultModel> GetPatientsParPraticien(string praticien, int take = 0, int skip = 0) { try { Logger.LogInfo("GetPatientsParPraticien : Start ."); if (string.IsNullOrEmpty(praticien)) { return(new Return <PatientResultModel>() .Error().AsValidationFailure(null, "Veuillez introduire votre praticien Cin.", "praticien") .WithDefaultResult()); } var totalCount = _rendezVousRepository.GetCount(); var totalPages = (take != 0) ? (int)Math.Ceiling((double)totalCount / take) : 0; var paginationHeader = new PaginationHeader { TotalCount = totalCount, TotalPages = totalPages }; var patients = (take == 0 && skip == 0) ? _rendezVousRepository .GetAll() .Where(x => x.Praticien.Email.Equals(praticien)) .Select(x => x.Patient) .ToList() .Distinct() : _rendezVousRepository .GetAll() .Where(x => x.Praticien.Email.Equals(praticien)) .Select(x => x.Patient) .Skip(skip) .Take(take) .Distinct() .ToList(); var data = new PatientResultModel(); patients.ForEach(account => { var patient = _patientRepository.GetAll().FirstOrDefault(p => p.Email.Equals(account.Email)); if (patient != null) { var dataModel = PatientWrapper.ConvertPatientEntityToDataModel(patient); data.Items.Add(dataModel); } else { //le patient peut être un praticien donc on sélectionne même les praticiens var prat = _praticienRepository.GetAll().FirstOrDefault(p => p.Email.Equals(account.Email)); var dataModel = PatientWrapper.ConvertPratientEntityToDataModel(prat); data.Items.Add(dataModel); } }); data.PaginationHeader = paginationHeader; Logger.LogInfo("Get Patients With Take And Skip Parameters : End --- Status : OK"); return(new Return <PatientResultModel>().OK().WithResult(data)); } catch (Exception) { throw; } }