예제 #1
0
        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
            }));
        }
예제 #2
0
        public Location GetLocation(HairSalonSearchVM hairSalonSearchVM)
        {
            string address = hairSalonSearchVM.Address;
            string city    = hairSalonSearchVM.City;
            string country = hairSalonSearchVM.SelectedCountry;

            return(unitOfWork.Locations.GetLocationWithCity(address, city, country));
        }
예제 #3
0
        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>());
        }
예제 #4
0
        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());
        }
예제 #5
0
        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);
        }
예제 #6
0
        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));
        }