private void CreateOrder() { _eventAggregator.GetEvent <OnOrderCreate>().Publish(new List <ProductInOrder>(ProductInOrderCollection)); ProductInOrderCollection.Clear(); CreateOrderCommand.RaiseCanExecuteChanged(); UnselectCommand.RaiseCanExecuteChanged(); }
private void CreateOrder() { order = new Order(); order.CustomerID = SelectedCustomer.CustomerID; order.EmployeeID = SelectedEmployee.EmployeeID; order.OrderDate = DateTime.Parse(OrderDate); using (var contextTransaction = _context.Database.BeginTransaction()) { try { _context.Orders.Add(order); int result = _context.SaveChanges(); //if (result > 0) OrderID = order.OrderID; _context.Order_Details.AddRange( new List <Order_Details>( ProductInOrderCollection.Select(p => new Order_Details { OrderID = order.OrderID, ProductID = p.ID, UnitPrice = p.UnitPrice, Quantity = p.Quantity, Discount = p.Discount }))); _context.SaveChanges(); contextTransaction.Commit(); } catch (Exception) { contextTransaction.Rollback(); } } _eventAggregator.GetEvent <NewOrderCreated>().Publish(order.OrderID); ProductInOrderCollection = null; //OrderID = null; OrderDate = String.Empty; SelectedCustomer = null; SelectedEmployee = null; TotalSum = string.Empty; CreateOrderCommand.RaiseCanExecuteChanged(); UnselectCommand.RaiseCanExecuteChanged(); }