/// <summary> /// Add new product object to the DataServiceContext, and associat the object with an existing ProductCategory. /// Changes are sent to the server using SaveChangesOptions.Batch so that all operations are sent in a single HTTP request. /// </summary> /// <param name="product">The product to be Added</param> public void AddProduct(Product product) { product.rowguid = Guid.NewGuid(); context.AddObject("Products", product); context.SetLink(product, "ProductCategory", product.ProductCategory); context.SaveChanges(SaveChangesOptions.Batch); }
/// <summary> /// Try to delete the specified product, if product cannot be deleted, return error message "Product Cannot be Deleted" /// </summary> /// <param name="product">The product to be deleted</param> public string DeleteProduct(Product product) { context.DeleteObject(product); try { context.SaveChanges(); } catch (DataServiceRequestException) { return "Product Cannot be Deleted"; } return null; }
public void UpdateProduct(Product product) { this.product = gateway.GetProducts(product.Name, product.ProductCategory)[0]; FormCreateMode = false; this.Title = "Edit " + product.Name; }
private void Window_Loaded(object sender, RoutedEventArgs e) { BindCategories(); if (FormCreateMode) { product = new Product(); } BindProduct(); }
/// <summary> /// This method assumes that all fields have been changed and updates the entire entity, including the association to ProductCategory. /// Changes are sent to the server using SaveChangesOptions.Batch so that all operations are sent in a single HTTP request. /// </summary> /// <param name="product">The product to be Updated</param> public void UpdateProduct(Product product) { ProductCategory newCategory = product.ProductCategory; context.SetLink(product, "ProductCategory", newCategory); context.UpdateObject(product); context.SaveChanges(SaveChangesOptions.Batch); }