private void EditOrderButton_OnClick(object sender, RoutedEventArgs e) { Button button = sender as Button; Order copy = new Order(button.DataContext as Order); var dialog = new AddModifyOrderDialog(copy, _viewModel.customizedProductRepository.CustomizedProductRepository.ToList(), _viewModel.Employees.ToList(), _viewModel.Customers.ToList(), _viewModel.Toppings.ToList(), _viewModel.Products.ToList()); dialog.Owner = this; dialog.ShowDialog(); if (dialog.DialogResult == true) { copy.OrderStatus = OrderStatus.Cooking; copy.CookingDeadline = DateTime.Parse("15/11/2017 9:00"); copy.DeliveryDeadline = DateTime.Parse("15/11/2017 9:00"); copy.OrderCreated = DateTime.Parse("15/11/2017 9:00"); copy.TotalPrice = 0; copy.Deliveryman = dialog.ModifyOrders.SelectedDeliveryman; copy.Customer = dialog.ModifyOrders.SelectedCustomer; copy.OrderedProducts = dialog.ModifyOrders.Order.OrderedProducts; for (int i = 0; i < _viewModel.Orders.Count; i++) { if (_viewModel.Orders[i].OrderId == copy.OrderId) { _viewModel.OrdersRepository.ChangeOrder(_viewModel.Orders[i], copy); _viewModel.Orders[i] = copy; DataContext = null; DataContext = _viewModel; } } } }
private void AddOrderButton_OnClick(object sender, RoutedEventArgs e) { var dialog = new AddModifyOrderDialog(null, _viewModel.customizedProductRepository.CustomizedProductRepository.ToList(), _viewModel.Employees.ToList(), _viewModel.Customers.ToList(), _viewModel.Toppings.ToList(), _viewModel.Products.ToList()); Order copy = new Order(); dialog.Owner = this; dialog.ShowDialog(); if (dialog.DialogResult == true) { copy.Deliveryman = dialog.ModifyOrders.SelectedDeliveryman; copy.Customer = dialog.ModifyOrders.SelectedCustomer; // wypełnienie pól not null niebędących w formularzu copy.OrderedProducts = dialog.ModifyOrders.Order.OrderedProducts; copy.OrderStatus = OrderStatus.Cooking; copy.CookingDeadline = DateTime.Parse("15/11/2017 9:00"); copy.DeliveryDeadline = DateTime.Parse("15/11/2017 9:00"); copy.OrderCreated = DateTime.Parse("15/11/2017 9:00"); copy.TotalPrice = 0; _viewModel.OrdersRepository.AddNewOrder(copy); _viewModel.Orders.Add(copy); DataContext = null; DataContext = _viewModel; } }