示例#1
0
        private async void AddProductButton_OnClick(object sender, RoutedEventArgs e)
        {
            var product = new Product();
            var dialog = new ProductDialog
            {
                DataContext = product
            };
            var result = await DialogHost.Show(dialog, "RootDialog");

            if ((bool)result
                && product.Name.Length > 0)
            {
                product.LastModification = DateTime.Now;

                Database.Database db = new Database.Database();
                db.Products.InsertOnSubmit(product);
                db.SubmitChanges();

                UpdateDataContexts();
            }
        }
示例#2
0
        private async void ProductEditBtn_OnClick(object sender, RoutedEventArgs e)
        {
            var product = ((FrameworkElement)sender).DataContext as Product;
            if (product == null)
                return;

            Database.Database db = new Database.Database();

            product = (from p in db.Products
                       where p.Id == product.Id
                       select p).Single();

            var dialog = new ProductDialog
            {
                DataContext = product
            };
            var result = await DialogHost.Show(dialog, "RootDialog");

            if ((bool) result
                && product.Name.Length > 0)
            {
                product.LastModification = DateTime.Now;
                db.SubmitChanges();
            }
            // TODO delete
            UpdateDataContexts();
        }