public async Task <ActionResult> Search() { if (Session["RegisteredUser"] == null) { countryApi = new CountryApiClient(); List <Country> countries = await countryApi.GetCountries(); SelectList selectListItemCountries = new SelectList(countries); HairSalonSearchVM hairSalonSearchVM = new HairSalonSearchVM() { Countries = selectListItemCountries }; return(View(hairSalonSearchVM)); } RegisteredUser registeredUser = (RegisteredUser)Session["RegisteredUser"]; return(await Search(new HairSalonSearchVM() { Address = registeredUser.Location.Address, City = registeredUser.Location.City.Name, SelectedCountry = registeredUser.Location.City.Country.Name })); }
public Location GetLocation(HairSalonSearchVM hairSalonSearchVM) { string address = hairSalonSearchVM.Address; string city = hairSalonSearchVM.City; string country = hairSalonSearchVM.SelectedCountry; return(unitOfWork.Locations.GetLocationWithCity(address, city, country)); }
public async Task <List <HairSalon> > GetHairSalonsNearMe(HairSalonSearchVM hairSalonSearchVM) { StringContent content = GetStringContent(hairSalonSearchVM); HttpClient request = new HttpClient(); HttpResponseMessage response = await request.PostAsync($"{ API_URL }/GetHairSalonsNearMe", content); if (response.IsSuccessStatusCode) { List <HairSalon> hairSalons = await response.Content.ReadAsAsync <List <HairSalon> >(); return(hairSalons); } return(new List <HairSalon>()); }
public async Task <Location> GetLocation(HairSalonSearchVM hairSalonSearchVM) { StringContent content = GetStringContent(hairSalonSearchVM); HttpClient request = new HttpClient(); HttpResponseMessage response = await request.PostAsync($"{API_URL}/GetLocation", content); if (response.IsSuccessStatusCode) { Location location = await response.Content.ReadAsAsync <Location>(); return(location); } return(new Location()); }
public async Task <IEnumerable <HairSalon> > GetHairSalonsNearMeAsync(HairSalonSearchVM hairSalonSearchVM) { List <HairSalon> hairSalonsNearMe = new List <HairSalon>(); string inputAddress = $"{hairSalonSearchVM.Address} {hairSalonSearchVM.City} {hairSalonSearchVM.SelectedCountry.Substring(5)}"; Address inputGeocodedAddress = await GetGeocodedAddress(inputAddress); IEnumerable <HairSalon> hairSalons = unitOfWork.HairSalons.GetHairSalonsWithLocationsAndWorkersAndOwners(); foreach (HairSalon hairSalon in hairSalons) { string hairSalonAddress = hairSalon.GetFormatedLocation(); Address hairSalonGeocodedAddress = await GetGeocodedAddress(hairSalonAddress); if (inputGeocodedAddress.DistanceBetween(hairSalonGeocodedAddress) < hairSalonSearchVM.Distance) { hairSalonsNearMe.Add(hairSalon); } } return(hairSalonsNearMe); }
public async Task <ActionResult> Search(HairSalonSearchVM hairSalonSearchVM) { if (ModelState.IsValid) { Session["SearchQuery"] = $"{hairSalonSearchVM.Address}, {hairSalonSearchVM.City}, {hairSalonSearchVM.SelectedCountry.Substring(5)} - {hairSalonSearchVM.Distance} km"; hairSalonApi = new HairSalonApiClient(); List <HairSalon> hairSalonsNearMe = await hairSalonApi.GetHairSalonsNearMe(hairSalonSearchVM); return(View("HairSalons", hairSalonsNearMe)); } countryApi = new CountryApiClient(); List <Country> countries = await countryApi.GetCountries(); SelectList selectListItemCountries = new SelectList(countries); hairSalonSearchVM.Countries = selectListItemCountries; return(View(hairSalonSearchVM)); }