private async void AddOrderButton_OnClick(object sender, RoutedEventArgs e) { var order = new Order { Color = 0xFFFFFF, Status = OrderStatus.Ready, IsOnSiteWithdraw = true, WithdrawDate = DateTime.Now }; var dialog = new OrderDialog { DataContext = order }; var result = await DialogHost.Show(dialog, "RootDialog"); if ((bool)result) { order.LastModification = DateTime.Now; order.WithdrawDate = dialog.GetDateTime(); Database.Database db = new Database.Database(); try { // TODO null exception foreach (var oe in dialog.ListOrderElements) { db.OrdersElements.InsertOnSubmit(oe); } db.Orders.InsertOnSubmit(order); db.SubmitChanges(); } catch (Exception exception) { Debug.WriteLine(exception); } UpdateDataContexts(); } }
private async void OrderEditBtn_OnClick(object sender, RoutedEventArgs e) { var order = ((FrameworkElement)sender).DataContext as Order; if (order == null) return; Database.Database db = new Database.Database(); order = (from c in db.Orders where c.Id == order.Id select c).Single(); // TODO try/catch var dialog = new OrderDialog { DataContext = order }; var result = await DialogHost.Show(dialog, "RootDialog"); if ((bool)result) { order.LastModification = DateTime.Now; db.SubmitChanges(); } // TODO delete UpdateDataContexts(); }