public void EditProduct(object item) { if (CanEditProduct(null)) { if (SelectedProduct != null) { ProductData productItem = new ProductData() { ProductID = SelectedProduct.ProductID, Name = ProductName, ProductNumber = ProductNumber, Color = Color, ListPrice = ListPrice, ProductDescription = ProductDescription, Quantity = Quantity, CategoryID = CategoryID, IsActive = ProductIsActive }; Product updatedProduct = ProductsClient.UpdateProduct(productItem); ProductData productInList = ProductList.First(p => p.ProductID == updatedProduct.ProductID); productInList.Name = updatedProduct.Name; productInList.Color = updatedProduct.Color; productInList.ListPrice = updatedProduct.ListPrice; productInList.ProductNumber = updatedProduct.ProductNumber; productInList.ProductDescription = updatedProduct.ProductDescription; productInList.Quantity = updatedProduct.Quantity; productInList.IsActive = updatedProduct.IsActive; productInList.SalesOrderCount = updatedProduct.SalesOrderItems.Count; productInList.CategoryID = (int)updatedProduct.ProductCategoryID; CategoryData category = CategoryList.FirstOrDefault(c => c.ProductCategoryID == (int)updatedProduct.ProductCategoryID); productInList.CategoryName = (category != null) ? category.Name : String.Empty; productInList.IsCategoryActive = (category != null) ? category.IsActive : false; } else { try { ProductData productItem = new ProductData() { ProductID = 0, Name = ProductName, CategoryID = CategoryID, Color = Color, ListPrice = ListPrice, ProductDescription = ProductDescription, ProductNumber = ProductNumber, Quantity = Quantity, IsActive = ProductIsActive }; Product updatedProduct = ProductsClient.UpdateProduct(productItem); if (updatedProduct != null) { ProductList.Add(new ProductData() { ProductID = updatedProduct.ProductID, Name = updatedProduct.Name, CategoryID = (int)updatedProduct.ProductCategoryID, Color = updatedProduct.Color, ListPrice = updatedProduct.ListPrice, ProductDescription = updatedProduct.ProductDescription, ProductNumber = updatedProduct.ProductNumber, Quantity = updatedProduct.Quantity, IsActive = updatedProduct.IsActive, SalesOrderCount = 0 }); } else { MessageBox.Show("Save failed."); } } catch (Exception ex) { Debug.WriteLine(ex.Message); } } } }