public async Task <bool> SavePathAsync(IEnumerable <City> cities) { bool result = true; using (var client = new HttpClient()) { client.BaseAddress = new Uri(this.UrlApi); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", await this.GetToken()); IList <CityDTO> citiesDTO = new List <CityDTO>(); foreach (var city in cities) { citiesDTO.Add(city.GetDTO()); } var content = new StringContent(JsonConvert.SerializeObject(citiesDTO), Encoding.UTF8, "application/json"); HttpResponseMessage response = await client.PostAsync(this.UrlApi + "SaveCities", content); var tokenObj = await response.Content.ReadAsStringAsync(); var token = JsonConvert.DeserializeObject <BaseTokenizedDTO>(tokenObj); await LocalStorageManagerService.UpdatePermanentItemAsync("Token", token.Token); result = response.IsSuccessStatusCode; } return(result); }
public async Task AddCityDialog_OnDialogClose(Map_AddCity map_AddCity) { this.RestaurantSearches = map_AddCity.RestaurantSearches; this.MuseumSearches = map_AddCity.MuseumSearches; map_AddCity.City.CityOrder = this.Cities.Count; map_AddCity.City.UserId = await LocalStorageManagerService.GetPermanentItemAsync("UserId"); this.Cities.Add(map_AddCity.City); if (this.MuseumSearches.Count == 0 && this.RestaurantSearches.Count == 0) { var serializedCities = JsonConvert.SerializeObject(this.Cities); await LocalStorageManagerService.DeletePermanentItemAsync("Cities"); await LocalStorageManagerService.SavePermanentItemAsync("Cities", serializedCities); } if (this.MuseumSearches.Count == 0 && map_AddCity.City.NeedsMuseum) { if (this.RestaurantSearches.Count == 0 && map_AddCity.City.NeedsRestaurant) { ShowUnSuccessAlert("Sorry! We couldn't find any restaurants, nor any museums in your area"); } else { ShowUnSuccessAlert("Sorry! We couldn't find any museums in your area"); } } else if (this.RestaurantSearches.Count == 0 && map_AddCity.City.NeedsRestaurant) { ShowUnSuccessAlert("Sorry! We couldn't find any restaurants in your area"); } ShowSuccessAlert("The city was successfully added to the route!"); }
protected async Task NewRoute() { this.Cities.Clear(); await JSRuntime.InvokeVoidAsync("removeDirections"); await LocalStorageManagerService.DeletePermanentItemAsync("Cities"); ShowSuccessAlert("Here we go! Now you can start all over again!"); StateHasChanged(); }
protected async Task SaveRoute() { if (this.Cities.Count > 0) { await CitiesDataService.SavePathAsync(Cities); await LocalStorageManagerService.DeletePermanentItemAsync("Cities"); ShowSuccessAlert("Route successfully saved!"); } else { ShowUnSuccessAlert("There is no route to be saved!"); } }
protected async Task RestaurantSelected(GoogleTextSearchDTO restaurant) { this.Cities[Cities.Count() - 1].SelectedRestaurant = restaurant; this.RestaurantSearches.Clear(); if (this.MuseumSearches.Count == 0 && this.RestaurantSearches.Count == 0) { var serializedCities = JsonConvert.SerializeObject(this.Cities); await LocalStorageManagerService.DeletePermanentItemAsync("Cities"); await LocalStorageManagerService.SavePermanentItemAsync("Cities", serializedCities); } await JSRuntime.InvokeVoidAsync("hideLocation"); ShowSuccessAlert("Restaurant selected"); StateHasChanged(); }
protected async Task GetUnsavedRoute() { var serializedCities = await LocalStorageManagerService.GetPermanentItemAsync("Cities"); if (serializedCities != null) { this.Cities = JsonConvert.DeserializeObject <List <City> >(serializedCities); await ShowRoute(); ShowSuccessAlert("The route was successfully restored!"); } else { ShowUnSuccessAlert("You have no route cached in your browser!"); } }
protected async Task GetRoutes() { var userId = await LocalStorageManagerService.GetPermanentItemAsync("UserId"); CityFilter cityFilter = new CityFilter { UserId = userId }; var result = (await CitiesDataService.GetRoutes(cityFilter.GetFilter())); if (result?.Routes.Count > 0) { LastRoutes = result; } else { ShowUnSuccessAlert("You have no routes saved in our DB!"); } StateHasChanged(); }
protected override async Task OnAfterRenderAsync(bool firstRender) { await LocalStorageManagerService.DeletePermanentItemAsync("Token"); }