public CUD() { CreateProductoCommand = new CommandDelegate ( (o) => { return(true); }, (o) => { var NewProduct = new EntitiesStandart.Products { ProductName = ProductName_BF, CategoryID = CategoryID_BF, UnitsInStock = UnitsInStock_BF, UnitPrice = UnitPrice_BF }; var Proxy = new NWindProxyService.Proxy(); NewProduct = Proxy.CreateProduct(NewProduct); ProductID = NewProduct.ProductID; } ); UpdateProductoCommand = new CommandDelegate ( (o) => { return(true); }, (o) => { var CurrentProducto = new EntitiesStandart.Products { ProductID = ProductID_BF, ProductName = ProductName_BF, CategoryID = CategoryID_BF, UnitsInStock = UnitsInStock_BF, UnitPrice = UnitPrice_BF }; var Proxy = new NWindProxyService.Proxy(); var Modified = Proxy.UpdateProduct(CurrentProducto); } ); DeleteProductoCommand = new CommandDelegate ( (o) => { return(true); }, (o) => { var Proxy = new NWindProxyService.Proxy(); var IsDeleted = Proxy.DeleteProduct(ProductID); if (IsDeleted) { ProductID = 0; ProductName = ""; CategoryID = 0; UnitsInStock = 0; UnitPrice = 0; } } ); }
private void InitializeViewModel() { Product = new ProductModel(); CreateProductCommand = new CommandDelegate ( (obj) => { return(true); }, (obj) => { var newProduct = new Entities.Product() { CategoryID = Product.CategoryID, ProductName = Product.ProductName, UnitPrice = Product.UnitPrice, UnitsInStock = Product.UnitsInStock }; var proxy = new NWindProxyService.Proxy(); newProduct = proxy.CreateProduct(newProduct); Product.ProductID = newProduct.ProductID; } ); UpdateProductCommand = new CommandDelegate ( (obj) => { return(true); }, (obj) => { var updateProduct = new Entities.Product() { ProductID = Product.ProductID, CategoryID = Product.CategoryID, ProductName = Product.ProductName, UnitPrice = Product.UnitPrice, UnitsInStock = Product.UnitsInStock }; var proxy = new NWindProxyService.Proxy(); var updated = proxy.UpdateProduct(updateProduct); if (updated) { HasError = false; Message = "The product has been updated correctly."; } else { HasError = true; Message = "The product could not be updated."; } } ); DeleteProductCommand = new CommandDelegate ( (obj) => { return(true); }, (obj) => { var proxy = new NWindProxyService.Proxy(); var deleted = proxy.DeleteProduct(Product.ProductID); if (deleted) { HasError = false; Product = new ProductModel(); Message = "The product has been deleted correctly."; } else { HasError = true; Message = "The product could not be deleted."; } } ); }