public ICommandResult Handle(RegisterOrderCommand command) { // Re-hidratando Customer var customer = _customerRepository.Get(command.CustomerId); var order = new Order(customer, command.DeliveryFee, command.Discount); foreach (var item in command.Items) { // Re-hidratando Product var product = _productRepository.Get(item.ProductId); var orderItem = new OrderItem(); orderItem.AddProduct(product, item.Quantity, product.Price); order.AddItem(orderItem); } AddNotifications(order.Notifications); if (order.IsValid()) { _orderRepository.Save(order); } return(new RegisterOrderCommandResult(order.Id)); }
public Order Create(CreateOrderCommand command, string email) { var user = _userRepository.GetByEmail(email); var orderItems = new List <OrderItem>(); foreach (var item in command.OrderItems) { var orderItem = new OrderItem(); var product = _productRepository.Get(item.Product); orderItem.AddProduct(product, item.Quantity, item.Price); orderItems.Add(orderItem); } var order = new Order(orderItems, user.Id); order.Place(); _orderRepository.Create(order); if (Commit()) { return(order); } return(null); }
public void Init() { _validItens = new List <OrderItem>(); var item = new OrderItem(); _product = new Product( description: "Produto Comum", price: 13.9m, quantityOnHand: 300, image: "", unitOfMeasurementId: Guid.NewGuid().ToString(), categoryId: Guid.NewGuid().ToString()); item.AddProduct(_product, 20, 30m); _validItens.Add(item); _validOrder = new Order( orderItens: _validItens, userId: Guid.NewGuid().ToString(), notes: "Nothing..."); }
static void Main(string[] args) { // Dados do Cliente //Instanciando Client Client client = new Client(); Console.WriteLine("Enter Client Data: "); Console.Write("Name: "); client.Name = Console.ReadLine(); Console.Write("E-mail: "); client.Email = Console.ReadLine(); Console.Write("Birth Date (DD/MM/YYYY): "); client.BirthDate = DateTime.Parse(Console.ReadLine()); // Criação da Ordem Console.WriteLine("Enter Order data:"); Console.Write("Status: "); OrderStatus status = Enum.Parse <OrderStatus>(Console.ReadLine()); // Instanciando Order e associando o Client Order order = new Order() { Moment = DateTime.Now, Status = status }; order.AddCliente(client); // Criação e Entrada dos ítens da Ordem Console.Write("How many items to this order?"); int qtdItemsOrder = int.Parse(Console.ReadLine()); for (int i = 1; i <= qtdItemsOrder; i++) { Console.WriteLine($"Enter #{i} item data:"); Console.Write("Product Name: "); string name = Console.ReadLine(); Console.Write("Product Price:"); double price = double.Parse(Console.ReadLine(), CultureInfo.InvariantCulture); Console.Write("Quantity: "); int quantity = int.Parse(Console.ReadLine()); // Instanciando Product Product produto = new Product() { Name = name, Price = price }; // Instanciando OrderItem OrderItem orderItem = new OrderItem() { Quantity = quantity, Price = price }; orderItem.AddProduct(produto); // Associando Product à OrdemItem // Adicionando a OrdemItem à Order order.AddItem(orderItem); } // Mostrando os resultados na Tela Console.WriteLine("ORDER SUMMARY:"); Console.WriteLine("Order Moment: " + order.Moment.ToString("dd/MM/yyyy HH:mm:ss")); Console.WriteLine("Order Status: " + order.Status); Console.WriteLine("Client: " + order.Cli.Name + " (" + order.Cli.BirthDate.ToString("dd/MM/yyyy") + ")" + " - " + order.Cli.Email); Console.WriteLine(order); }