Exemple #1
0
        public async Task <OrderProcess> Add(OrderProcess model)
        {
            var entity = _menuUnitRepository.Add(model);
            await _menuUnitRepository.SaveChangeAsync();

            return(model);
        }
Exemple #2
0
        public void ProcessMessage(IHandlerContext <RegisterOrderProcessCommand> context)
        {
            var message = context.Message;

            var orderProcess = new OrderProcess
            {
                OrderId         = null,
                InvoiceId       = null,
                CustomerName    = message.CustomerName,
                CustomerEMail   = message.CustomerEMail,
                TargetSystem    = message.TargetSystem,
                TargetSystemUri = message.TargetSystemUri
            };

            orderProcess.GenerateOrderNumber();

            foreach (var quotedProduct in message.QuotedProducts)
            {
                orderProcess.AddItem(new OrderProcessItem(quotedProduct.ProductId, quotedProduct.Description,
                                                          quotedProduct.Price));
            }

            var status = new OrderProcessStatus("Cooling Off");

            orderProcess.AddStatus(status);

            using (_databaseContextFactory.Create(ProcessManagementData.ConnectionStringName))
            {
                _repository.Add(orderProcess);
            }

            context.Publish(new OrderProcessRegisteredEvent
            {
                OrderProcessId  = orderProcess.Id,
                QuotedProducts  = message.QuotedProducts,
                CustomerName    = message.CustomerName,
                CustomerEMail   = message.CustomerEMail,
                OrderNumber     = orderProcess.OrderNumber,
                OrderDate       = orderProcess.DateRegistered,
                OrderTotal      = orderProcess.Total(),
                Status          = status.Status,
                StatusDate      = status.StatusDate,
                TargetSystem    = message.TargetSystem,
                TargetSystemUri = message.TargetSystemUri
            });

            context.Send(new AcceptOrderProcessCommand
            {
                OrderProcessId = orderProcess.Id
            }, c => c.Defer(DateTime.Now.AddSeconds(10)).Local());
        }