public List <GetDoctorDto> filterDoctors(FilterDoctorDto filterdoctorDto) { var allDoctor = TheUnitOfWork.DoctorRepo.GetAllDoctorForSearch(); if (filterdoctorDto.specailtyid != null) { allDoctor = allDoctor.Where(d => d.specialtyId == filterdoctorDto.specailtyid); } if (filterdoctorDto.CityId != null) { allDoctor = allDoctor.Where(d => d.clinic.CityId == filterdoctorDto.CityId); } if (filterdoctorDto.AreaId != null) { allDoctor = allDoctor.Where(d => d.clinic.AreaId == filterdoctorDto.AreaId); } if (filterdoctorDto.Name != null) { allDoctor = allDoctor.Where(d => d.User.FullName.Contains(filterdoctorDto.Name)); } //expression tree allDoctor = allDoctor.Where(d => (filterdoctorDto.title.Count > 0? filterdoctorDto.title.Contains(d.TitleDegree) : true)); allDoctor = allDoctor.Where(d => (filterdoctorDto.fee.Count > 0 ? filterdoctorDto.fee.Contains(new feelimit { MiniMoney = d.clinic.Fees, MaxMoney = d.clinic.Fees }) : true) && (filterdoctorDto.subspecails.Count > 0? filterdoctorDto.subspecails.Any(i => d.DoctorSubSpecialization.Any(dsup => dsup.subSpecializeId == i)) :true) ).ToList(); return(Mapper.Map <List <GetDoctorDto> >(allDoctor)); }
public List <DoctorDto> GetByFilter([FromBody] FilterDoctorDto filter) { var now = DateTime.Now; using (var dbContext = new ApplicationDbContext()) { int?userId = GetUserId(); if (filter.ClinicId != null) { userId = filter.ClinicId; } return(dbContext.Clinic_Doctors .Where(d => d.UserId == userId) .Where(d => filter.Id == null || d.Id == filter.Id) .Where(d => filter.FullName == null || $"{d.FirstName} {d.LastName}".Contains(filter.FullName) || $"{d.LastName} {d.FirstName}".Contains(filter.FullName)) .Where(d => filter.SpecialtyId == null || d.SpecialtyId == filter.SpecialtyId) .Where(d => filter.SubspecialtyId == null || d.SubspecialtyId == filter.SubspecialtyId) .Select(d => new DoctorDto { Id = d.Id, FirstName = d.FirstName, LastName = d.LastName, Email = d.Email, PhoneNumber = d.PhoneNumber, SpecialtyId = d.SpecialtyId, SpecialtyDescription = d.Specialty.Data.Description, SubspecialtyId = d.SubspecialtyId, SubspecialtyDescription = d.Subspecialty != null ? d.Subspecialty.Data.Description : "Ninguna", ConsultationLength = d.ConsultationLength, State = d.WorkingHours.Any(wh => wh.DayNumber == now.DayOfWeek && wh.Start <= now.TimeOfDay && now.TimeOfDay <= wh.End), WorkingHours = d.WorkingHours.Select(wh => new WorkingHoursDto { DayNumber = wh.DayNumber, Start = wh.Start, End = wh.End }).OrderBy(wh => wh.DayNumber).ToList(), Appointments = d.Appointments.OrderBy(a => a.DateTime).Take(10).Select(a => a.DateTime).ToList() }).ToList()); } }
[HttpPost("FilterDoctors")] //{specailtyid}/{titles} public IActionResult FilterDoctors(FilterDoctorDto filterdoctorDto) //int specailtyid,List<string> titles { List <GetDoctorDto> doctors = this._doctorAppService.filterDoctors(filterdoctorDto); foreach (var doctor in doctors) { var _services = _doctor_DoctorServiceAppService.GetDoctorServices(doctor.UserId); var _subSpecails = _doctorSubSpecialization.GetSubSpecialtyByDoctorId(doctor.UserId); var _clinic = _clinicAppService.GetByStringId(doctor.UserId); double doctorAverageRate = _ratingAppService.getPublicRateForDoctor(doctor.UserId); doctor.services = _services; doctor.subspecails = _subSpecails; doctor.clinic = _clinic; doctor.clinicAreaName = _areaAppService.GetById(_clinic.AreaId).Name; doctor.clinicCityName = _cityAppService.Get(_clinic.CityId).Name; IEnumerable <GetWorkingDayDTO> workingDaysDTOs = _workingDayAppService.GetWorkingDaysForDoctor(doctor.UserId); doctor.workingDays = workingDaysDTOs.ToList(); doctor.averageRate = doctorAverageRate; } /* if (filterdoctorDto.fee.Count > 0) * { * foreach (var doctor in doctors.ToList()) * { * bool del = true; * foreach (var fee in filterdoctorDto.fee) * { * if (fee.MiniMoney <= doctor.clinic.Fees && doctor.clinic.Fees < fee.MaxMoney) * { * del = false; * break; * } * } * if(del) * doctors.Remove(doctor); * } * * } * * if (filterdoctorDto.subspecails.Count > 0) * { * foreach (var doctor in doctors.ToList()) * { * bool del = true; * foreach (var sub in filterdoctorDto.subspecails) * { * foreach (var item in doctor.subspecails) * { * if (item.Name == sub) * { * del = false; * break; * } * } * if (del==false) * break; * } * if (del) * doctors.Remove(doctor); * } * * }*/ return(Ok(doctors)); }