private void Products_CurrentItemChanged(ProductNotifyExtended oldProduct, ProductNotifyExtended newProduct) { if (newProduct != null) { newProduct.PropertyChanged += Product_PropertyChanged; } if (oldProduct != null) { oldProduct.PropertyChanged -= Product_PropertyChanged; } }
private void ValidateUniqueName(ProductNotifyExtended product) { string errorMessage = "The product name must be unique"; if (!IsProductNameUnique(product)) { product.ExternalErrors.Add(errorMessage); } else { product.ExternalErrors.Remove(errorMessage); } }
private bool IsProductNameUnique(ProductNotifyExtended product) { return(Products.Count(p => p.Id != product.Id && p.Name != string.Empty && p.Name == product.Name) == 0); }