public ICommandResult Handle(CreateOrderCommand command) { command.Validate(); if (command.Invalid) { return(new GenericCommandResult(false, "Pedido inválido", null)); } var customer = _customerRepository.Get(command.Customer); var deliveryFee = _deliveryFeeRepository.Get(command.ZipCode); var discount = _discountRepository.Get(command.PromoCode); var products = _productRepository.Get(ExtractGuids.Extract(command.Items)).ToList(); var order = new Order(customer, deliveryFee, discount); foreach (var item in command.Items) { var product = products.Where(x => x.Id == item.Product).FirstOrDefault(); order.AddItem(product, item.Quantity); } AddNotifications(order.Notifications); if (Invalid) { return(new GenericCommandResult(false, "Falha ao gerar o pedido", Notifications)); } _orderRepository.Save(order); return(new GenericCommandResult(true, $"Pedido {order.Number} gerado com sucesso", order)); }
public ICommandResult Handle(CreateOrderCommand command) { // Fail Fast Validation command.Validate(); if (command.Invalid) { return(new GenericCommandResult(false, "Invalid Order", command.Notifications)); } var customer = _customerRepository.Get(command.Customer); var deliveryFee = _deliveryRepository.Get(command.ZipCode); var discount = _discountRepository.Get(command.PromoCode); // Generate Order var products = _productRepository.Get(ExtractGuids.Extract(command.Items)).ToList(); var order = new Order(customer, deliveryFee, discount); foreach (var item in command.Items) { var product = products.Where(x => x.Id == item.Product).FirstOrDefault(); order.AddItem(product, item.Quantity); } AddNotifications(order.Notifications); if (Invalid) { return(new GenericCommandResult(false, "Failure generate order", Notifications)); } _orderRepository.Save(order); return(new GenericCommandResult(true, $"Order {order.Number} generate successful", order)); }
public ICommandResult Handle(CreateOrderCommand command) { command.Validate(); if (command.Invalid) { return(new GenericCommandResult(false, "Pedido inválido", command.Notifications)); } // 1. Recupera o cliente var customer = _customerRepository.Get(command.Customer); // 2. Calcula a taxa de entrega var deliveryFee = _deliveryFeeRepository.Get(command.ZipCode); // 3. Obtém o cupom de desconto var discount = _discountRepository.Get(command.PromoCode); if (command.Items.Count == 0) { return(new GenericCommandResult(false, "Não foram selecionados itens de pedido", command.Notifications)); } // 4. Gera o pedido var products = _productRepository.Get(ExtractGuids.Extract(command.Items)).ToList(); var order = new Order(customer, deliveryFee, discount); foreach (var item in command.Items) { var product = products.Where(x => x.Id == item.Product).FirstOrDefault(); order.AddItem(product, item.Quantity); } // 5. Agrupa as notificações AddNotifications(order.Notifications); // 6. Verifica se não adicionou o pedido corretamente if (Invalid) { return(new GenericCommandResult(false, "Falha ao gerar o pedido", Notifications)); } // 7. Retorna o resultado _orderRepository.Save(order); return(new GenericCommandResult(true, $"Pedido {order.Number} inserido com sucesso", order)); }
public ICommandResult Handle(CreateOrderCommand command) { // 0. Fail, Fast, Validation command.Validate(); if (command.Invalid) { return(new GenericCommandResult(false, "Pedido Inválido", command.Notifications)); } // 1. Recuperar o cliente var customer = _customerRepository.Get(command.Customer); // 2. Calcular a taxa de entrega var deliveryFree = _deliveryFreeRepository.Get(command.ZipCode); // 3. Obtém cupom de desconto var discount = _discountRepository.Get(command.PromoCode); // 4. Gerar o pedido var products = _productRepository.Get(ExtractGuids.Extract(command.Items)).ToList(); var order = new Order(customer, deliveryFree, discount); foreach (var item in command.Items) { var product = products.Where(x => x.Id == item.Product).FirstOrDefault(); order.AddItem(product, item.Quantity); } // 5. Agrupar as notificações AddNotifications(order.Notifications); // 6. Verifica se deu tudo certo if (Invalid) { return(new GenericCommandResult(false, "Falha oa gerar pedido", Notifications)); } // 7. Retorna o resultado _orderRepository.Save(order); return(new GenericCommandResult(true, $"Pedido {order.Number} gerado com sucesso", order)); }
public ICommandResult Handler(CreateOrderCommand command) { //Fail Fast Validate command.Validate(); if (!command.Valid) { return(new GenericCommandResult(false, "Pedido Inválido", command.Notifications)); } // 1º Recupera Cliente var customer = _customer.Get(command.Customer); // 2º Calcula Taxa de entrega var delivery = _delivery.Get(command.ZipCode); // 3º Obtém cupom de desconto var discount = _discount.Get(command.PromoCode); var products = _product.Get(ExtractGuids.Extract(command.Items)).ToList(); var order = new Order(customer, delivery, discount); //4º Gera o pedido foreach (var item in command.Items) { var product = products.Where(x => x.Id == item.Product).FirstOrDefault(); order.AddItem(product, item.Quantity); } //5º Agrupa as notificações AddNotifications(order.Notifications); //6º Valida se deu certo if (Invalid) { return(new GenericCommandResult(false, "Falha ao gerar pedido", order.Notifications)); } //7º retorna o resultado _orderRepository.Save(order); return(new GenericCommandResult(true, $"Pedido {order.Number} gerado com sucesso!", order)); }
public ICommandResult Handle(CreatePedidoCommand command) { // Fail Fast Validation command.validate(); if (command.Invalid) { return(new GenericCommandResult(false, "Pedido inválido", null)); } // 1. Recupera o cliente var aluno = _alunoRepository.Get(command.Aluno); // 2. Calcula a taxa de entrega var delivery = _deliveryRepository.Get(command.ZipCode); // 3. Obtém o cupom de desconto var desconto = _descontoRepository.Get(command.PromoCode); // 4. Gera o pedido var cursos = _cursoRepository.Get(ExtractGuids.Extract(command.Items)).ToList(); var pedido = new Pedido(aluno, delivery, desconto); foreach (var item in command.Items) { var curso = cursos.Where(x => x.Id == item.Curso).FirstOrDefault(); pedido.AddItem(curso, item.Quantidade); } // 5. Agrupa as notificações AddNotifications(pedido.Notifications); // 6. Verifica se deu tudo certo if (Invalid) { return(new GenericCommandResult(false, "Falha ao gerar o pedido", Notifications)); } // 7. Retorna o resultado _pedidoRepository.Save(pedido); return(new GenericCommandResult(true, $"Pedido {pedido.Numero} gerado com sucesso", pedido)); }
public ICommandResult Handle(CreateOrderCommand command) { // Fail Fast Validation command.Validate(); if (command.Invalid) { return(new GenericCommandResult(false, "Pedido Inválido", command.Notifications)); } // Recuperar Cliente var customer = _customerRepository.Get(command.Customer); // Calcular Frete var deliveryFee = _deliveryFeeRepository.Get(command.ZipCode); // Calcular Desconto var discount = _discountRepository.Get(command.PromoCode); // Gerar Pedido var products = _productRepository.Get(ExtractGuids.Extract(command.Items)).ToList(); var order = new Order(customer, deliveryFee, discount); foreach (var item in command.Items) { var product = products.Where(x => x.Id == item.Product).FirstOrDefault(); order.AddItem(product, item.Quantity); } // Agrupar notificacoes AddNotifications(order.Notifications); // Verifica se deu tudo certo if (Invalid) { return(new GenericCommandResult(false, "Falha ao gerar pedido", Notifications)); } // salva e retorna resultado _orderRepository.Save(order); return(new GenericCommandResult(true, $"Pedido {order.Number} gerado com Sucesso", order)); }
public ICommandResult Handle(CreateOrderCommand command) { // Fail Fast Validation command.Validate(); if (command.Invalid) { return(new GenericCommandResult(false, "Pedido inválido", command.Notifications)); } // Recupera o cliente var customer = _customerRepository.Get(command.Customer); // Calcular a taxa de entrega var deliveryFee = _deliveryFeeRepository.Get(command.ZipCode); // Obtém o cupom de desconto var discount = _discountRepository.Get(command.PromoCode); // Gera o pedido var products = _productRepository.Get(ExtractGuids.Extract(command.Items)).ToList(); var order = new Order(customer, deliveryFee, discount); foreach (var item in command.Items) { var product = products.Where(x => x.Id == item.Product).FirstOrDefault(); order.AddItem(product, item.Quantity); } // Agrupa as notificações AddNotifications(order, customer, discount); if (Invalid) { return(new GenericCommandResult(false, "Falha ao gerar o pedido", Notifications)); } // Salva ordem de compra _orderRepository.Save(order); // Retorna o resultado do handler return(new GenericCommandResult(true, $"Pedido {order.Number} gerado com sucesso", order)); }
//Cadastrar a reserva não quer dizer que ela foi comprada // Tera um handler para confirmar reserva // Ai sim é persistido, mas para outras pessoas, a reserva ja foi feita public ICommandResult Handle(CreateReservaCommand command) { command.Validate(); if (command.Invalid) { return(new GenericCommandResult(false, "Dados incorretos", command.Notifications)); } var cliente = _clienteRepository.GetById(command.ClienteId); var sessao = _sessaoRepository.GetById(command.SessaoId); var poltronas = _sessaoRepository.GetPoltronasByIds(sessao.Id, ExtractGuids.Extract(command)); //Verificar se poltronas estão ocupadas if (IsPoltronasOcuped(poltronas)) { return(new GenericCommandResult(false, "Algumas poltronas selecionadas já estão ocupadas", poltronas)); } var reserva = new Reserva(cliente, sessao); var ingressos = CreateIngressos(command.Ingressos, poltronas); reserva.AdicionarIngresso(ingressos); AddNotifications(reserva); if (Invalid) { return(new GenericCommandResult(false, "Problema ao gerar reserva", this.Notifications)); } _reservaRepository.Add(reserva); return(new GenericCommandResult(true, "Reserva cadastrado, aguardando pagamento", reserva)); //Verifica o estado das poltronas //Utilizar Dapper ou buscar estas informações na tela }