public void RefreshList() { if (string.IsNullOrEmpty(this.Filter)) { var myListProductItemViewModel = MyProducts.Select(p => new ProductItemViewModel { Description = p.Description, ImageArray = p.ImageArray, ImagePath = p.ImagePath, IsAvailable = p.IsAvailable, Price = p.Price, ProductId = p.ProductId, PublishOn = p.PublishOn, Remarks = p.Remarks, }); this.Products = new ObservableCollection <ProductItemViewModel>(myListProductItemViewModel.OrderBy(p => p.Description)); } else { var myListProductItemViewModel = this.MyProducts.Select(p => new ProductItemViewModel { Description = p.Description, ImageArray = p.ImageArray, ImagePath = p.ImagePath, IsAvailable = p.IsAvailable, Price = p.Price, ProductId = p.ProductId, PublishOn = p.PublishOn, Remarks = p.Remarks, }).Where(p => p.Description.ToLower().Contains(this.Filter.ToLower())).ToList(); this.Products = new ObservableCollection <ProductItemViewModel>(myListProductItemViewModel.OrderBy(p => p.Description)); } }
public void RefreshList() { var myListProductItemViewModel = MyProducts.Select(p => new ProductItemViewModel { Description = p.Description, ImageArray = p.ImageArray, ImagePath = p.ImagePath, IsAvailable = p.IsAvailable, Price = p.Price, ProductId = p.ProductId, PublishOn = p.PublishOn, Remarks = p.Remarks, }); /*para funciones ne lista*/ //var myList = new List<ProductItemViewModel>(); //foreach (var item in list) //{ // myList.Add(new ProductItemViewModel { // }); //} /**/ this.Products = new ObservableCollection <ProductItemViewModel>( myListProductItemViewModel.OrderBy(p => p.Description)); }
public void RefreshList() { var MylistProductItemViewModel = MyProducts.Select(p => new ProductItemViewModel { Description = p.Description, ImageArray = p.ImageArray, ImagePath = p.ImagePath, Price = p.Price, ProductId = p.ProductId, IsAvailable = p.IsAvailable, PublishOn = p.PublishOn, Remarks = p.Remarks, }); ////Se comenta este código porque no es muy practico hacerlo ya que puede ser tardado //var Mylist = new List<ProductItemViewModel>(); //foreach (var item in list) //{ // Mylist.Add(new ProductItemViewModel // { // }); //} //no se puede mandar una lista de productos, se tiene que mandar una lista de productItemView Model //hay dos maneras de hacerlo, una con un foreach que se encontrará comentado ya que en este caso es demasiado lento y //afecta en el performance y la otra manera es con una expresion lambda asignando cada uno de los atributos a la lista de //ProductItemViewModel this.Products = new ObservableCollection <ProductItemViewModel>(MylistProductItemViewModel.OrderBy(p => p.Description)); }
private async void LoadProducts() { this.IsRefreshing = true; var connection = await this.apiService.CheckConnection(); if (!connection.IsSuccess) { this.IsRefreshing = false; await Application.Current.MainPage.DisplayAlert(Languages.Error, connection.Message, Languages.Accept); return; } var response = await this.apiService.GetList <Product>( "https://salesapijonalexjm.azurewebsites.net", "/api", "/Products", Settings.TokenType, Settings.AccessToken); this.IsRefreshing = false; if (!response.IsSuccess)// si funciono sigue pasando { await Application.Current.MainPage.DisplayAlert( Languages.Error, response.Message, Languages.Accept); return; } this.MyProducts = (List <Product>)response.Result; this.RefreshList(); var myListProductItemViewModel = MyProducts.Select(p => new ProductItemViewModel { Description = p.Description, ImageArray = p.ImageArray, ImagePath = p.ImagePath, IsAvailable = p.IsAvailable, Price = p.Price, ProductId = p.ProductId, PublishOn = p.PublishOn, Remarks = p.Remarks, }); this.Products = new ObservableCollection <ProductItemViewModel>(myListProductItemViewModel.OrderBy(p => p.Description)); this.IsRefreshing = false; }
public void RefreshList() { var mylistProductItemViewModel = MyProducts.Select(p => new ProductItemViewModel { Description = p.Description, ImageArray = p.ImageArray, ImagePath = p.ImagePath, IsAvailable = p.IsAvailable, Price = p.Price, ProductId = p.ProductId, PublishOn = p.PublishOn, Remarks = p.Remarks, }); this.Products = new ObservableCollection <ProductItemViewModel>(mylistProductItemViewModel.OrderBy(p => p.Description)); }
public void RefreshList() { if (string.IsNullOrEmpty(this.Filter)) { var myListProductItemViewModel = MyProducts.Select(p => new ProductItemViewModel { description = p.description, imageArray = p.imageArray, imagePath = p.imagePath, available = p.available, price = p.price, productId = p.productId, publishOn = p.publishOn, remark = p.remark, category = p.category }); this.Products = new ObservableCollection <ProductItemViewModel>( myListProductItemViewModel.OrderBy(p => p.description)); } else { var myListProductItemViewModel = MyProducts.Select(p => new ProductItemViewModel { description = p.description, imageArray = p.imageArray, imagePath = p.imagePath, available = p.available, price = p.price, productId = p.productId, publishOn = p.publishOn, remark = p.remark, category = p.category }).Where(p => p.description.ToLower().Contains(this.Filter.ToLower())).ToList(); this.Products = new ObservableCollection <ProductItemViewModel>( myListProductItemViewModel.OrderBy(p => p.description)); } }