private async void LoadRecommendationsByIdRestaurant() { this.IsRefreshing = true; var connection = await this.apiService.CheckConnection(); if (!connection.IsSuccess) { await Application.Current.MainPage.DisplayAlert(Languages.Error, connection.Message, Languages.Accept); return; } var url = Application.Current.Resources["UrlAPI"].ToString(); var prefix = Application.Current.Resources["UrlPrefix"].ToString(); var controller = Application.Current.Resources["UrlRecommendationsController"].ToString(); var response = await this.apiService.GetList <Recommendation>(url, prefix, controller, Settings.TokenType, Settings.AccessToken); if (!response.IsSuccess) { this.IsRefreshing = false; await Application.Current.MainPage.DisplayAlert(Languages.Error, response.Message, Languages.Accept); return; } ; this.MyRecommendations = (List <Recommendation>)response.Result; this.MyRecommendations = MyRecommendations.Where(r => r.IdRestaurant == this.restaurant.IdRestaurant).ToList(); this.RefreshList(); this.IsRefreshing = false; }
public async Task <MyRecommendations> GetRecommendationsForBook( [ID(nameof(Book))] long id, BookByIdDataLoader dataLoader, [Service] IGetClaimsProvider claimsProvider, [ScopedService] BookRefDbContext context, CancellationToken cancellationToken) { var library = context.Libraries .First(e => e.Id == claimsProvider.LibraryId); var result = new MyRecommendations(); var source = await dataLoader.LoadAsync(id, cancellationToken); result.SourceBook = source; result.BookRecommedations = library.BookRecommedations.Where(e => e.SourceBookId == source.Id).ToList(); result.PersonRecommedations = library.PersonRecommedations.Where(e => e.SourceBookId == source.Id).ToList(); return(result); }
public void RefreshList() { if (string.IsNullOrEmpty(this.Filter)) { var myListRecommendationsItemViewModel = MyRecommendations.Select(r => new RecommendationItemViewModel { RecommendationUser = r.RecommendationUser, ImagePathRecomm = r.ImagePathRecomm, Score = r.Score, DateRecomm = r.DateRecomm, IdRestaurant = r.IdRestaurant }); this.Recommendations = new ObservableCollection <RecommendationItemViewModel>( myListRecommendationsItemViewModel.OrderByDescending(r => r.DateRecomm)); if (this.MyRestaurants == null) { } else { foreach (Recommendation recommendation in this.Recommendations) { recommendation.RecommendationUser = recommendation.RecommendationUser; recommendation.ImagePathRecomm = recommendation.ImagePathRecomm; recommendation.Score = recommendation.Score; recommendation.DateRecomm = recommendation.DateRecomm; recommendation.IdRestaurant = recommendation.IdRestaurant; recommendation.Restaurant = this.MyRestaurants.Where(r => r.IdRestaurant == recommendation.IdRestaurant).FirstOrDefault(); } } } else { var myListRecommendationsItemViewModel = MyRecommendations.Select(r => new RecommendationItemViewModel { RecommendationUser = r.RecommendationUser, ImagePathRecomm = r.ImagePathRecomm, Score = r.Score, DateRecomm = r.DateRecomm, IdRestaurant = r.IdRestaurant }).Where(r => r.RecommendationUser.ToLower().Contains(this.Filter.ToLower())).ToList();; this.Recommendations = new ObservableCollection <RecommendationItemViewModel>( myListRecommendationsItemViewModel.OrderByDescending(r => r.DateRecomm)); if (this.MyRestaurants == null) { } else { foreach (Recommendation recommendation in this.Recommendations) { recommendation.RecommendationUser = recommendation.RecommendationUser; recommendation.ImagePathRecomm = recommendation.ImagePathRecomm; recommendation.Score = recommendation.Score; recommendation.DateRecomm = recommendation.DateRecomm; recommendation.IdRestaurant = recommendation.IdRestaurant; recommendation.Restaurant = this.MyRestaurants.Where(r => r.IdRestaurant == recommendation.IdRestaurant).FirstOrDefault(); } } } }