private void NotCompetedOrderCommandExecuter(object parameter) { Order order = GetOrdersForNotCompletedCommand(parameter); if (order == null) { return; } order.IsCompleted = true; context.SaveChanges(); OnProperyChanged("NotCompletedOrders"); OnProperyChanged("CompletedOrders"); OrderWindowViewModel.Instance.UpdateOrder(); }
public void CreateOrder(object parameter) { using (var context = new KursachDBContext()) { Order lastOrder = context.Orders.OrderByDescending(o => o.Id).FirstOrDefault(); int newId = 1; if (lastOrder != null) { newId = lastOrder.Id + 1; } Order newOrder = new Order() { Id = newId, Discount = Cost > 30 ? 10 : 0, IsCompleted = false, IsGiven = false, OrderDate = DateTime.Now }; if (Cost > 50 && Cost < 100) { newOrder.Discount = 5; } context.Orders.Add(newOrder); foreach (var product in OrderProducts) { ProductsOrder currEntity = context.ProductsOrders.Create(); currEntity.OrderId = newOrder.Id; currEntity.ProductId = product.Id; context.ProductsOrders.Add(currEntity); } context.SaveChanges(); WorkerWindowViewModel.Instance.UpdateView(); OrderWindowViewModel.Instance.UpdateOrder(); CashRepairWindow wnd = new CashRepairWindow(); try { wnd.ShowDialog(); } catch { } finally { OrderProducts = new ObservableCollection <Product>(); OnProperyChanged(nameof(OrderProducts)); } } }