public static ProductCategory UpdateCategory(CategoryData category)
 {
     ProductCategory result = null;
     BicycleWorldServiceClient client = new BicycleWorldServiceClient();
     try
     {
         client.ClientCredentials.UserName.UserName = LoginUser.Current.Username;
         client.ClientCredentials.UserName.Password = LoginUser.Current.Password;
         result = client.UpdateCategory(new ProductCategory()
         {
             Name = category.Name,
             IsActive = category.IsActive,
             ProductCategoryID = category.ProductCategoryID
         });
         client.Close();
     }
     catch (FaultException)
     {
         client.Abort();
     }
     catch (CommunicationException)
     {
         client.Abort();
     }
     catch (TimeoutException)
     {
         client.Abort();
     }
     catch { throw; }
     return result;
 }
        public void EditCategory(object item)
        {
            if (CanEditCategory(null))
            {
                if (SelectedCategory != null)
                {
                    CategoryData categoryItem = new CategoryData()
                    {
                        ProductCategoryID = SelectedCategory.ProductCategoryID,
                        Name = CategoryName,
                        IsActive = CategoryIsActive
                    };
                    ProductCategory updatedProductCategory = CategoriesClient.UpdateCategory(categoryItem);

                    CategoryData categoryInList = CategoryList.FirstOrDefault(cat => cat.ProductCategoryID == updatedProductCategory.ProductCategoryID);
                    categoryInList.Name = updatedProductCategory.Name;
                    categoryInList.IsActive = updatedProductCategory.IsActive;
                }
                else
                {
                    try
                    {
                        CategoryData categoryItem = new CategoryData()
                        {
                            ProductCategoryID = 0,
                            Name = CategoryName,
                            IsActive = CategoryIsActive
                        };
                        ProductCategory updatedProductCategory = CategoriesClient.UpdateCategory(categoryItem);

                        if (updatedProductCategory != null)
                        {
                            CategoryList.Add(new CategoryData()
                            {
                                ProductCategoryID = updatedProductCategory.ProductCategoryID,
                                Name = updatedProductCategory.Name,
                                IsActive = updatedProductCategory.IsActive,
                                ProductCount = updatedProductCategory.ProductCount
                            });
                        }
                        else
                        { MessageBox.Show("Save failed."); }
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine(ex.Message);
                    }
                }
            }
        }
 public void CreateNewCategory(object item)
 {
     SelectedCategory = null;
 }