public ActionResult Search(SearchModel model, int?page) { var pageNumber = (page ?? 1) - 1; var pageSize = 5; int totalCount; int specilityId = 0; if (model == null) { model = new SearchModel(); } if (TempData["SearchModel"] != null) { model = (SearchModel)TempData["SearchModel"]; } var searchTerms = model.q ?? ""; if (!string.IsNullOrWhiteSpace(model.q)) { searchTerms = model.q.Trim(); } if (!string.IsNullOrWhiteSpace(searchTerms)) { specilityId = _specialityService.GetAllSpeciality(true).Where(s => s.Title == searchTerms).FirstOrDefault().Id; } var data = _doctorService.SearchDoctor(pageNumber, pageSize, out totalCount, model.geo_location, specilityId, model.geo_distance); var searchModel = new SearchModel { AvailableSpeciality = GetSpecialityList(), directory_type = model.directory_type, keyword = model.keyword, SpecialityId = model.SpecialityId, geo_location = model.geo_location }; var searchViewModel = data.Select(doc => new TempDoctorViewModel { Doctors = doc, Address = _addressService.GetAllAddressByUser(doc.DoctorId).FirstOrDefault(), AddressLine = GetAddressline(_addressService.GetAllAddressByUser(doc.DoctorId).FirstOrDefault()), Specialities = _specialityService.GetDoctorSpecilities(doc.DoctorId) }).ToList(); totalCount = searchViewModel.Count; IPagedList <TempDoctorViewModel> pageDoctors = new StaticPagedList <TempDoctorViewModel>(searchViewModel, pageNumber + 1, pageSize, totalCount); ViewBag.SearchModel = searchModel; return(View(pageDoctors)); }
public PartialViewResult _DoctorBox(SearchModel model, int?page) { var searchViewModel = new List <TempDoctorViewModel>(); var pageNumber = (page ?? 1) - 1; var pageSize = 5; int totalCount; int specilityId = 0; string searchByName = string.Empty; if (model == null) { model = new SearchModel(); } var searchTerms = model.q ?? ""; if (!string.IsNullOrWhiteSpace(model.q)) { searchTerms = model.q.Trim(); } if (!string.IsNullOrWhiteSpace(searchTerms)) { try { specilityId = _specialityService.GetAllSpeciality(true).Where(s => s.Title == searchTerms).FirstOrDefault().Id; } catch { specilityId = 0; } if (specilityId == 0) { searchByName = searchTerms; } } var data = _doctorService.SearchDoctor(pageNumber, pageSize, out totalCount, model.geo_location, specialityId: specilityId, searchByName: searchByName, maxFee: model.maxfee, minFee: model.minfee, SortBy: model.SortBy, searchCriteria: model.searchCriteria ); if (data != null) { searchViewModel = data.Select(doc => new TempDoctorViewModel { Doctors = doc, Address = _addressService.GetAllAddressByUser(doc.DoctorId).FirstOrDefault(), AddressLine = GetAddressline(_addressService.GetAllAddressByUser(doc.DoctorId).FirstOrDefault()), YearOfExperience = GetTotalExperience(doc.Experience), Qualification = GetQualification(doc.Education), ListSpecialities = GetSpecialities(_specialityService.GetDoctorSpecilities(doc.DoctorId)), ReviewOverviewModel = PrepareDoctorReviewOverviewModel(doc), AddPictureModel = GetProfilePicture(doc.DoctorId), DoctorPictureModels = GetAllPictures(doc.DoctorId) }).ToList(); } IPagedList <TempDoctorViewModel> pageDoctors = new StaticPagedList <TempDoctorViewModel>(searchViewModel, pageNumber + 1, pageSize, totalCount); ViewBag.SearchModel = PrepareSearchModel(model); ViewBag.IsHomePageSearch = false; return(PartialView(pageDoctors)); }