private void UpdateProducts() { var allProducts = _productsCatalog.GetProducts(); foreach (var product in allProducts) { var language1 = _resourcesProvider.GetResource("Lang" + product.Language1); var language2 = _resourcesProvider.GetResource("Lang" + product.Language2); var any = _resourcesProvider.GetResource("Any"); if (((language1 == _CurrentLanguage1 || _CurrentLanguage1 == any) && ((language2 == _CurrentLanguage2 || _CurrentLanguage2 == any)) || ((language2 == _CurrentLanguage1 || _CurrentLanguage1 == any) && ((language1 == _CurrentLanguage2 || CurrentLanguage2 == any))))) { if (!product.IsPurchased && !Products.Contains(product) && !product.RemovedFromSale) { Products.Add(product); } else if (product.IsPurchased && !PurchasedProducts.Contains(product)) { PurchasedProducts.Add(product); } } else { if (!product.IsPurchased && Products.Contains(product)) { Products.Remove(product); } else if (product.IsPurchased && PurchasedProducts.Contains(product)) { PurchasedProducts.Remove(product); } } if (!Products.Contains(_currentProduct) || !PurchasedProducts.Contains(_currentProduct)) { //Если ранее выбранный словарь не попал в отфильтрованный список то выставляем самый первый в списке в качестве выбранного if (PurchasedProducts.Count != 0) { CurrentProduct = PurchasedProducts[0]; } else if (Products.Count != 0) { CurrentProduct = Products[0]; } else { // } } } }
public bool IsProductPurchased(int productId) => PurchasedProducts.Contains(productId);