public static Product UpdateProduct(ProductData product) { Product result = null; BicycleWorldServiceClient client = new BicycleWorldServiceClient(); try { client.ClientCredentials.UserName.UserName = LoginUser.Current.Username; client.ClientCredentials.UserName.Password = LoginUser.Current.Password; result = client.UpdateProduct(new Product() { ProductID = product.ProductID, Name = product.Name, ProductNumber = product.ProductNumber, Color = product.Color, ListPrice = product.ListPrice, ProductDescription = product.ProductDescription, Quantity = product.Quantity, ProductCategoryID = product.CategoryID, IsActive = product.IsActive }); client.Close(); } catch (FaultException) { client.Abort(); } catch (CommunicationException) { client.Abort(); } catch (TimeoutException) { client.Abort(); } catch { throw; } return result; }
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); } } } }
public void CreateNewProduct(object item) { SelectedProduct = null; }