public async Task <bool> UpdateComponentOrder(ComponentsOrderPOCO order) { return(await Connection.UpdateAsync(order) == 1); }
public async Task <bool> AddComponentOrder(ComponentsOrderPOCO order) { return(await Connection.SaveAsync(order)); }
private async void SaveButton_Click(object sender, RoutedEventArgs e) { if (double.TryParse(PriceTextBox.Text, out var price)) { PriceTextBox.BorderBrush = (SolidColorBrush) new BrushConverter().ConvertFrom("#FFABADB3"); var halted = false; var components = new Dictionary <long, int>(); foreach (var componentBoxes in AllComponents) { long id; int count; if (long.TryParse(componentBoxes.Key.Text, out id)) { componentBoxes.Key.Background = (SolidColorBrush) new BrushConverter().ConvertFrom("#FFABADB3"); } else { halted = true; componentBoxes.Key.Background = Brushes.Red; } if (int.TryParse(componentBoxes.Value.Text, out count)) { componentBoxes.Value.Background = (SolidColorBrush) new BrushConverter().ConvertFrom("#FFABADB3"); } else { halted = true; componentBoxes.Value.Background = Brushes.Red; } if (!halted && id != -1 && MainWindow.AllComponents.Find(x => x.Id == id) != null) { if (components.ContainsKey(id)) { components[id] += count; } else { components.Add(id, count); } } } if (halted) { return; } var result = new ComponentsOrderPOCO { Components = components, Price = price, OrderDate = OrderDatePicker.SelectedDate.Value, DateOfArrival = ArrivalDatePicker.SelectedDate.Value, Completed = false }; await DatabaseProvider.Database.AddComponentOrder(result); MainWindow.AllComponentsOrders.Add(result); ((MainWindow)this.Owner).RefreshComponentsOrdersDataGrid(); ((MainWindow)this.Owner).ComponentsOrdersDatagrid_SelectionChanged(null, null); this.Close(); } else { PriceTextBox.BorderBrush = Brushes.Red; } }