public void SerializeDeserialize()
        {
            // arrange
            OrderDocument order     = new OrderDocument();
            OrderItem     orderItem = new OrderItem();

            orderItem.Id          = 3;
            orderItem.Description = "Soup of the day";
            orderItem.Price       = 6.95m;
            orderItem.Quantity    = 2;
            order.AddItem(orderItem);

            // act
            string        json            = order.Serialize();
            OrderDocument rehydratedOrder = new OrderDocument(json);

            // assert

            Assert.That(rehydratedOrder.GetItems().Count, Is.EqualTo(1));
            OrderItem rehydratedOrderItem = rehydratedOrder.GetItems()[0];

            Assert.That(rehydratedOrderItem.Id, Is.EqualTo(3));
            Assert.That(rehydratedOrderItem.Description, Is.EqualTo("Soup of the day"));
            Assert.That(rehydratedOrderItem.Price, Is.EqualTo(6.95m));
            Assert.That(rehydratedOrderItem.Quantity, Is.EqualTo(2));
        }
Example #2
0
 public static OrderDto AsDto(this OrderDocument document)
 => new OrderDto
 {
     Id      = document.Id,
     BuyerId = document.BuyerId,
     Address = new AddressDto
     {
         City     = document.Address.City,
         Street   = document.Address.Street,
         Province = document.Address.Province,
         Country  = document.Address.Country,
         ZipCode  = document.Address.ZipCode
     },
     Status     = document.Status.ToString().ToLowerInvariant(),
     TotalPrice = document.TotalPrice,
     CreatedAt  = document.CreatedAt,
     Items      = document.Items.Select(item => new OrderItemDto
     {
         Id        = item.Id,
         Name      = item.Name,
         Quantity  = item.Quantity,
         UnitPrice = item.UnitPrice,
         Price     = item.Price
     })
 };
Example #3
0
        private void EditorOnButtonClick(object sender, ButtonPressedEventArgs buttonPressedEventArgs)
        {
            try
            {
                var restClient = (OrdersDocumentsRestClient)DataProcessor.GetRestClient("OrdersDocumentsRestClient");
                var o          = gridViewDocuments.GetRow(gridViewDocuments.FocusedRowHandle);
                var od         = o as OrderDocumentInfoDecorator;

                OrderDocument orderDocument = restClient.GetOrderDocument(_orderUniqueNumber, od.Code);

                string filePath = Path.Combine(Path.GetTempPath(), orderDocument.Name);
                File.WriteAllBytes(filePath, orderDocument.Content);
                Process.Start(new ProcessStartInfo {
                    FileName = filePath, UseShellExecute = true
                });
            }
            catch (LogicalApiException e)
            {
                MessageBox.Show(String.Format("Ошибка. Код: {0}. Сообщение: {1}", e.Code, e.Message));
            }
            catch (Exception e)
            {
                MessageBox.Show(String.Format("Ошибка. {0}", e.Message));
            }
        }
        public void Update(OrderDocument document, string email)
        {
            yvalidatedentryEmail.Text = email;

            this.document = document;
            UpdateEmails();
        }
 protected Message(OrderDocument order, Guid correlationId, Guid causationId, Guid?id = null)
 {
     Order         = order;
     Id            = id ?? Guid.NewGuid();
     CorrelationId = correlationId;
     CausationId   = causationId;
 }
Example #6
0
        public void Handle(OrderCompleted orderCompleted)
        {
            OrderDocument order = orderCompleted.Order;

            //Console.WriteLine("Order completed: {0}", orderCompleted.CorrelationId);
            count++;
            total += order.Total;
        }
        protected override async Task ExecuteInternalAsync(CancellationToken stoppingToken)
        {
            OrderDocument document = await orderRepository.PeekAsync().ConfigureAwait(false);

            if (document != null && await GenerateParcelsAsync(document.Order).ConfigureAwait(false))
            {
                await orderRepository.Delete(document.Id).ConfigureAwait(false);
            }
        }
Example #8
0
        private void UpdateNodes()
        {
            SelectedOrdersDocumentVMNode resultAlias = null;

            Vodovoz.Domain.Orders.Order orderAlias = null;
            Counterparty  counterpartyAlias        = null;
            OrderDocument orderDocumentAlias       = null;
            DeliveryPoint deliveryPointAlias       = null;

            var query = UoW.Session.QueryOver <OrderDocument>(() => orderDocumentAlias);

            Counterparty client = entryreferencevm1.GetSubject <Counterparty>();

            if (client != null)
            {
                query.Where(() => counterpartyAlias.Id == client.Id);
            }

            int orderId = default(int);

            if (int.TryParse(yvalidatedentry1.Text, out orderId))
            {
                //query.Where(() => orderAlias.Id == orderId);
                query.WhereRestrictionOn(() => orderAlias.Id).IsLike(orderId);
            }

            Documents = query
                        .JoinAlias(() => orderDocumentAlias.Order, () => orderAlias)
                        .JoinAlias(() => orderAlias.Client, () => counterpartyAlias)
                        .JoinAlias(() => orderAlias.DeliveryPoint, () => deliveryPointAlias)
                        .Where(() =>
                               orderDocumentAlias.GetType() == typeof(BillDocument) ||
                               orderDocumentAlias.GetType() == typeof(DoneWorkDocument) ||
                               orderDocumentAlias.GetType() == typeof(EquipmentTransferDocument) ||
                               orderDocumentAlias.GetType() == typeof(InvoiceBarterDocument) ||
                               orderDocumentAlias.GetType() == typeof(InvoiceDocument) ||
                               orderDocumentAlias.GetType() == typeof(InvoiceContractDoc) ||
                               orderDocumentAlias.GetType() == typeof(UPDDocument) ||
                               orderDocumentAlias.GetType() == typeof(DriverTicketDocument) ||
                               orderDocumentAlias.GetType() == typeof(Torg12Document) ||
                               orderDocumentAlias.GetType() == typeof(ShetFacturaDocument)
                               )
                        .SelectList(list => list
                                    .Select(() => orderAlias.Id).WithAlias(() => resultAlias.OrderId)
                                    .Select(() => orderAlias.DeliveryDate).WithAlias(() => resultAlias.OrderDate)
                                    .Select(() => counterpartyAlias.Id).WithAlias(() => resultAlias.ClientId)
                                    .Select(() => counterpartyAlias.Name).WithAlias(() => resultAlias.ClientName)
                                    .Select(() => orderDocumentAlias.Id).WithAlias(() => resultAlias.DocumentId)
                                    .Select(() => orderDocumentAlias.GetType()).WithAlias(() => resultAlias.DocumentTypeString)
                                    .Select(() => deliveryPointAlias.CompiledAddress).WithAlias(() => resultAlias.AddressString)
                                    ).OrderBy(() => orderAlias.DeliveryDate).Desc
                        .TransformUsing(Transformers.AliasToBean <SelectedOrdersDocumentVMNode>())
                        .List <SelectedOrdersDocumentVMNode>().ToList();

            datatreeviewOrderDocuments.SetItemsSource(Documents);
        }
Example #9
0
 private OrderSummeryViewModel ToOrderSummeryViewModel(OrderDocument o)
 {
     return(new OrderSummeryViewModel
     {
         ordernumber = o.OrderId,
         total = o.OrderItems.Sum(e => e.UnitPrice * e.Quantity),
         date = o.OrderDate,
         status = o.Status
     });
 }
Example #10
0
 public IMinion Create(OrderDocument order)
 {
     if (order.IsDodgyCustomer)
     {
         return(new DodgyMinion(_bus));
     }
     else
     {
         return(new RegularMinion(_bus));
     }
 }
Example #11
0
        public async Task When(OrderStartedDomainEvent @event)
        {
            var doc = new OrderDocument();

            doc.Address    = @event.Order.Address.ToAddressDocument();
            doc.OrderItems = @event.Order.OrderItems.ToOrderItemDocumenList();
            doc.OrderId    = @event.Order.Id;
            doc.OrderDate  = @event.Order.OrderDate;
            doc.Status     = @event.Order.OrderState.ToString();
            await queryStore.Upsert(doc);
        }
Example #12
0
        public void Handle(PayForOrder orderPricedMessage)
        {
            OrderDocument order = orderPricedMessage.Order;

            unpaidOrders.Add(order.Id, orderPricedMessage);
            _next.Publish(new OrderReadyForPayment(orderPricedMessage.Order)
            {
                MessageId     = Guid.NewGuid(),
                CorrelationId = orderPricedMessage.CorrelationId,
                CausationId   = orderPricedMessage.CausationId
            });
        }
        public void DeserializeSerialize()
        {
            // arrange
            string jsonOrder = "{\r\n  \"items\": [],\r\n  \"ingredients\": [\r\n    \"salt\",\r\n    \"pepper\"\r\n  ],\r\n  \"vip\": true\r\n}";

            // act
            OrderDocument order             = new OrderDocument(jsonOrder);
            string        reserializedOrder = order.Serialize();

            //  Assert
            Assert.That(reserializedOrder, Is.EqualTo(jsonOrder));
        }
Example #14
0
 public static Order AsEntity(this OrderDocument document)
 => new Order(
     document.Id,
     document.BuyerId,
     new Address(
         document.Address.City,
         document.Address.Street,
         document.Address.Province,
         document.Address.Country,
         document.Address.ZipCode),
     document.Items.Select(item => new OrderItem(item.Name, item.Quantity, item.UnitPrice)),
     document.Status,
     document.Version);
        public void Then_a_cook_food_command_should_be_sent()
        {
            var bus           = new Mock <IBus>();
            var midger        = new RegularMinion(bus.Object);
            var orderDocument = new OrderDocument();
            var correlationId = Guid.NewGuid();
            var messageId     = Guid.NewGuid();

            midger.Handle(new OrderPlaced(orderDocument, correlationId, Guid.NewGuid(), messageId));

            bus.Verify(f => f.Publish(It.Is <CookFood>(c => c.Order == orderDocument &&
                                                       c.CorrelationId == correlationId &&
                                                       c.CausationId == messageId)));
        }
Example #16
0
            public async void Should_Return_200_When_Found()
            {
                var order = new OrderDocument
                {
                    OrderDate = DateTimeOffset.Parse("2020-07-01T19:00:00Z", CultureInfo.InvariantCulture),
                    Lines     = new[]
                    {
                        new OrderDocument.OrderLine {
                            ProductId = 5, Amount = 1
                        },
                        new OrderDocument.OrderLine {
                            ProductId = 7, Amount = 5
                        }
                    }
                };

                progOrderActor.SetResponseForRequest <OrderActor.GetOrderById>(request =>
                                                                               new OrderActor.OrderFound {
                    Id = 501, Document = order
                });

                IActionResult result = await Subject.GetOrder(
                    new PrivateApiController.GetOrderRequest {
                    Id = 501
                });

                result.Should().BeOfType <OkObjectResult>()
                .Which.Value.Should().BeEquivalentTo(
                    new PrivateApiController.GetOrderResponse
                {
                    Id        = 501,
                    OrderDate = DateTimeOffset.Parse("2020-07-01T19:00:00Z", CultureInfo.InvariantCulture),
                    Lines     = new[]
                    {
                        new PrivateApiController.GetOrderResponse.OrderLine {
                            ProductId = 5, Amount = 1
                        },
                        new PrivateApiController.GetOrderResponse.OrderLine {
                            ProductId = 7, Amount = 5
                        }
                    }
                });

                progOrderActor.GetRequest <OrderActor.GetOrderById>()
                .Should().BeEquivalentTo(
                    new OrderActor.GetOrderById {
                    Id = 501
                });
            }
        public void PlaceOrder(LineItem item)
        {
            var order = new OrderDocument
            {
                OrderNumber = Guid.NewGuid(),
                Waiter      = _name
            };

            //order.AddLineItem(item);
            order.LineItems.Add(item);

            order.IsDodgyCustomer = DateTime.UtcNow.Ticks % 2 == 0;

            _bus.Publish(new OrderPlaced(order, Guid.NewGuid(), Guid.Empty));
        }
        public async Task <string> AddDocumentToOrderAsync(IFormFile document, string orderId, string userId, string orderNumber)
        {
            var fileId = await this.filesService.UploadToFileSystemAsync(document, "documents\\service\\orders\\" + orderNumber, "Service Document");

            var newUserDocument = new OrderDocument
            {
                UserId     = userId,
                DocumentId = fileId,
                OrderId    = orderId,
            };

            await this.dbOrderDocument.AddAsync(newUserDocument);

            await this.dbOrderDocument.SaveChangesAsync();

            return(newUserDocument.Id);
        }
Example #19
0
        public void Handle(CookOrder newOrder)
        {
            OrderDocument order = newOrder.Order;

            Thread.Sleep(_sleep);
            order.AddIngredient("Salt");
            order.AddIngredient("Pepper");
            order.AddIngredient("Tomatoes");
            order.AddIngredient("Chorizo");
            order.AddIngredient("Sugar");
            _bus.Publish(new OrderCooked(order)
            {
                MessageId     = Guid.NewGuid(),
                CorrelationId = newOrder.CorrelationId,
                CausationId   = newOrder.MessageId
            });
        }
Example #20
0
        public void Handle(PriceOrder meal)
        {
            OrderDocument order = meal.Order;

            order.SubTotal = order.GetItems().Sum(item => item.Price * item.Quantity);
            order.Tax      = order.SubTotal * 0.2m;
            order.Total    = order.Tax + order.SubTotal;

            var messageId = Guid.NewGuid();

            _bus.Publish(new OrderPriced(order)
            {
                MessageId     = messageId,
                CorrelationId = meal.CorrelationId,
                CausationId   = meal.MessageId
            });
        }
Example #21
0
        public void GetOrderDocuments()
        {
            var restClient = CreateRestClient();

            OrderDocument orderDocument = restClient.GetOrderDocument("E2E17" /*Order Number*/, "E2EF4" /*Document Number*/);

            Assert.NotNull(orderDocument);

            //Сохраняем присланные байты в файл
            string filePath = Path.Combine(Path.GetTempPath(), orderDocument.Name /*Это имя вполне подойдет для названия файла*/);

            File.WriteAllBytes(filePath, orderDocument.Content);

            //Запускаем файл в связанном приложении
            Process.Start(new ProcessStartInfo {
                FileName = filePath, UseShellExecute = true
            });
        }
Example #22
0
        private OrderViewModel ToOrderViewModel(OrderDocument order)
        {
            string seperator = "-";

            return(new OrderViewModel()
            {
                address = order.Address.Country + seperator
                          + order.Address.City + seperator
                          + order.Address.Street + seperator
                          + order.Address.State + seperator
                          + order.Address.ZipCode,
                orderitems = order.OrderItems.Select(e => ToOrderItemViewModel(e)).ToList(),
                buyername = order.BuyerInfo.BuyerName,
                date = order.OrderDate,
                ordernumber = order.OrderId,
                total = order.OrderItems.Sum(e => e.Quantity * e.UnitPrice)
            });
        }
Example #23
0
        public void PlaceOrder(IList <Tuple <int, int> > items, Guid orderId)
        {
            OrderDocument newOrder = new OrderDocument {
                Id = orderId
            };

            newOrder.IsDodgy = (rnd.Next(0, 100) > 80);

            foreach (var item in items)
            {
                MenuItem mItem = _menu.GetItem(item.Item1);
                newOrder.AddItem(new OrderItem {
                    Id = item.Item1, Description = mItem.Description, Quantity = item.Item2, Price = mItem.Price
                });
            }

            _bus.Publish(new OrderPlaced(newOrder)
            {
                MessageId = Guid.NewGuid(), CorrelationId = orderId, CausationId = Guid.Empty
            });
        }
        public bool HaveSendedEmailForBill(int orderId)
        {
            IList <OrderDocumentEmail> result;

            using (var uow = UnitOfWorkFactory.CreateWithoutRoot($"[ES]Получение списка отправленных писем"))
            {
                OrderDocumentEmail orderDocumentEmailAlias = null;
                OrderDocument      orderDocumentAlias      = null;

                result = uow.Session.QueryOver <OrderDocumentEmail>(() => orderDocumentEmailAlias)
                         .JoinAlias(() => orderDocumentEmailAlias.OrderDocument, () => orderDocumentAlias)
                         .Where(() => orderDocumentAlias.Order.Id == orderId)
                         .JoinQueryOver(ode => ode.StoredEmail)
                         .Where(se => se.State != StoredEmailStates.SendingError &&
                                se.State != StoredEmailStates.Undelivered)
                         .WithSubquery.WhereExists(
                    QueryOver.Of <BillDocument>()
                    .Where(bd => bd.Id == orderDocumentEmailAlias.OrderDocument.Id)
                    .Select(bd => bd.Id))
                         .List();
            }

            return(result.Any());
        }
Example #25
0
        public async Task Upsert(OrderDocument order)
        {
            var existing = await GetOrderAsync(order.OrderId);

            var b = new BsonDocument("$set", order.ToBsonDocument());

            try
            {
                if (existing != null)
                {
                    await collection?.UpdateOneAsync <OrderDocument>
                        (e => e.OrderId == order.OrderId, b);
                }
                else
                {
                    await collection?.InsertOneAsync(order);
                }
            }
            catch (Exception ex)
            {
                logger.LogError("$Error while upsering doc in Mongo " + ex.Message);
                throw  new Exception(ex.Message);
            }
        }
Example #26
0
            public void Should_Return_Order_When_Found()
            {
                var document = new OrderDocument
                {
                    OrderDate = DateTimeOffset.Parse("2020-07-01T19:00:00Z", CultureInfo.InvariantCulture),
                    Lines     = new[]
                    {
                        new OrderDocument.OrderLine {
                            ProductId = 5, Amount = 1
                        },
                        new OrderDocument.OrderLine {
                            ProductId = 7, Amount = 5
                        }
                    }
                };

                progDatastoreActor.SetResponseForRequest <RelationalDataStoreActor.ExecuteScalar>(request =>
                                                                                                  new RelationalDataStoreActor.ScalarResult(JsonSerializer.Serialize(document)));

                Subject.Tell(input);

                Kit.ExpectMsg <OrderActor.OrderFound>().Should().BeEquivalentTo(
                    new OrderActor.OrderFound
                {
                    Id       = 501,
                    Document = document
                });

                progDatastoreActor.GetRequest <RelationalDataStoreActor.ExecuteScalar>()
                .Should().BeEquivalentTo(new RelationalDataStoreActor.ExecuteScalar(
                                             DataStoreStatements.GetOrderById,
                                             new
                {
                    Id = 501
                }));
            }
Example #27
0
 public OrderPriced(OrderDocument order, Guid correlationId, Guid causationId, Guid?id = null)
     : base(order, correlationId, causationId, id)
 {
 }
 public PayForOrder(OrderDocument order)
 {
     _order = order;
 }
        public void ResendEmailWithErrorSendingStatus(DateTime date)
        {
            using (var uowLocal = UnitOfWorkFactory.CreateWithoutRoot())
            {
                var configuration = uowLocal.GetAll <InstanceMailingConfiguration>().FirstOrDefault();

                var dateCriterion = Projections.SqlFunction(
                    new SQLFunctionTemplate(
                        NHibernateUtil.Date,
                        "Date(?1)"
                        ),
                    NHibernateUtil.Date,
                    Projections.Property <StoredEmail>(x => x.SendDate)
                    );
                ICriterion dateResctict   = Restrictions.Eq(dateCriterion, date.Date);
                ICriterion dateResctictGe = Restrictions.Ge(dateCriterion, date.Date);

                #region OrderDocument

                OrderDocumentEmail orderDocumentEmailAlias      = null;
                OrderDocumentEmail orderDocumentEmailInnerAlias = null;
                OrderDocument      orderDocumentAlias           = null;
                OrderDocument      orderDocumentAliasInner      = null;

                var resendedOrderDocumentQuery = QueryOver.Of <OrderDocumentEmail>(() => orderDocumentEmailInnerAlias)
                                                 .JoinQueryOver(ode => ode.StoredEmail)
                                                 .Where(x => x.State != StoredEmailStates.SendingError)
                                                 .And(dateResctictGe)
                                                 .JoinAlias(() => orderDocumentEmailInnerAlias.OrderDocument, () => orderDocumentAliasInner)
                                                 .Where(() => orderDocumentAliasInner.Order.Id == orderDocumentAlias.Order.Id)
                                                 .Select(o => o.Id);

                var errorSendedOrderDocumentQuery = uowLocal.Session.QueryOver <OrderDocumentEmail>(() => orderDocumentEmailAlias)
                                                    .JoinQueryOver(ode => ode.StoredEmail)
                                                    .Where(se => se.State == StoredEmailStates.SendingError)
                                                    .And(dateResctict)
                                                    .JoinAlias(() => orderDocumentEmailAlias.OrderDocument, () => orderDocumentAlias)
                                                    .WithSubquery.WhereNotExists(resendedOrderDocumentQuery)
                                                    .Future();

                #endregion

                #region Order OrderWithoutShipmentForDebt

                OrderWithoutShipmentForDebtEmail orderWithoutShipmentForDebtEmailAlias      = null;
                OrderWithoutShipmentForDebtEmail orderWithoutShipmentForDebtEmailInnerAlias = null;
                OrderWithoutShipmentForDebt      orderWithoutShipmentForDebtAlias           = null;
                OrderWithoutShipmentForDebt      orderWithoutShipmentForDebtAliasInner      = null;

                var resendedOrderWithoutShipmentForDebtQuery = QueryOver.Of <OrderWithoutShipmentForDebtEmail>(() => orderWithoutShipmentForDebtEmailInnerAlias)
                                                               .JoinQueryOver(ode => ode.StoredEmail)
                                                               .Where(x => x.State != StoredEmailStates.SendingError)
                                                               .And(dateResctictGe)
                                                               .JoinAlias(() => orderWithoutShipmentForDebtEmailInnerAlias.OrderWithoutShipmentForDebt, () => orderWithoutShipmentForDebtAliasInner)
                                                               .Where(() => orderWithoutShipmentForDebtAliasInner.Id == orderWithoutShipmentForDebtAlias.Id)
                                                               .Select(o => o.Id);

                var errorSendedOrderWithoutShipmentForDebtEmailQuery = uowLocal.Session
                                                                       .QueryOver <OrderWithoutShipmentForDebtEmail>(() => orderWithoutShipmentForDebtEmailAlias)
                                                                       .JoinQueryOver(ode => ode.StoredEmail)
                                                                       .Where(se => se.State == StoredEmailStates.SendingError)
                                                                       .And(dateResctict)
                                                                       .JoinAlias(() => orderWithoutShipmentForDebtEmailAlias.OrderWithoutShipmentForDebt, () => orderWithoutShipmentForDebtAlias)
                                                                       .WithSubquery.WhereNotExists(resendedOrderWithoutShipmentForDebtQuery)
                                                                       .Future();

                #endregion

                #region Order OrderWithoutShipmentForAdvancePayment

                OrderWithoutShipmentForAdvancePaymentEmail orderWithoutShipmentForAdvancePaymentEmailAlias      = null;
                OrderWithoutShipmentForAdvancePaymentEmail orderWithoutShipmentForAdvancePaymentEmailInnerAlias = null;
                OrderWithoutShipmentForAdvancePayment      orderWithoutShipmentForAdvancePaymentAlias           = null;
                OrderWithoutShipmentForAdvancePayment      orderWithoutShipmentForAdvancePaymentAliasInner      = null;

                var resendedOrderWithoutShipmentForAdvancePaymentQuery = QueryOver.Of <OrderWithoutShipmentForAdvancePaymentEmail>(() => orderWithoutShipmentForAdvancePaymentEmailInnerAlias)
                                                                         .JoinQueryOver(ode => ode.StoredEmail)
                                                                         .Where(x => x.State != StoredEmailStates.SendingError)
                                                                         .And(dateResctictGe)
                                                                         .JoinAlias(() => orderWithoutShipmentForAdvancePaymentEmailInnerAlias.OrderWithoutShipmentForAdvancePayment, () => orderWithoutShipmentForAdvancePaymentAliasInner)
                                                                         .Where(() => orderWithoutShipmentForAdvancePaymentAliasInner.Id == orderWithoutShipmentForAdvancePaymentAlias.Id)
                                                                         .Select(o => o.Id);

                var errorSendedOrderWithoutShipmentForAdvancePaymentEmailQuery = uowLocal.Session
                                                                                 .QueryOver <OrderWithoutShipmentForAdvancePaymentEmail>(() => orderWithoutShipmentForAdvancePaymentEmailAlias)
                                                                                 .JoinQueryOver(ode => ode.StoredEmail)
                                                                                 .Where(se => se.State == StoredEmailStates.SendingError)
                                                                                 .And(dateResctict)
                                                                                 .JoinAlias(() => orderWithoutShipmentForAdvancePaymentEmailAlias.OrderWithoutShipmentForAdvancePayment, () => orderWithoutShipmentForAdvancePaymentAlias)
                                                                                 .WithSubquery.WhereNotExists(resendedOrderWithoutShipmentForAdvancePaymentQuery)
                                                                                 .Future();

                #endregion

                #region Order OrderWithoutShipmentForPayment

                OrderWithoutShipmentForPaymentEmail orderWithoutShipmentForPaymentEmailAlias      = null;
                OrderWithoutShipmentForPaymentEmail orderWithoutShipmentForPaymentEmailInnerAlias = null;
                OrderWithoutShipmentForPayment      orderWithoutShipmentForPaymentAlias           = null;
                OrderWithoutShipmentForPayment      orderWithoutShipmentForPaymentAliasInner      = null;

                var resendedOrderWithoutShipmentForPaymentQuery = QueryOver.Of <OrderWithoutShipmentForPaymentEmail>(() => orderWithoutShipmentForPaymentEmailInnerAlias)
                                                                  .JoinQueryOver(ode => ode.StoredEmail)
                                                                  .Where(x => x.State != StoredEmailStates.SendingError)
                                                                  .And(dateResctictGe)
                                                                  .JoinAlias(() => orderWithoutShipmentForPaymentEmailInnerAlias.OrderWithoutShipmentForPayment, () => orderWithoutShipmentForPaymentAliasInner)
                                                                  .Where(() => orderWithoutShipmentForPaymentAliasInner.Id == orderWithoutShipmentForPaymentAlias.Id)
                                                                  .Select(o => o.Id);

                var errorSendedOrderWithoutShipmentForPaymentEmailQuery = uowLocal.Session
                                                                          .QueryOver <OrderWithoutShipmentForPaymentEmail>(() => orderWithoutShipmentForPaymentEmailAlias)
                                                                          .JoinQueryOver(ode => ode.StoredEmail)
                                                                          .Where(se => se.State == StoredEmailStates.SendingError)
                                                                          .And(dateResctict)
                                                                          .JoinAlias(() => orderWithoutShipmentForPaymentEmailAlias.OrderWithoutShipmentForPayment, () => orderWithoutShipmentForPaymentAlias)
                                                                          .WithSubquery.WhereNotExists(resendedOrderWithoutShipmentForPaymentQuery)
                                                                          .Future();

                #endregion

                var errorSendedCounterpartyEmails = errorSendedOrderDocumentQuery
                                                    .Union <CounterpartyEmail>(errorSendedOrderWithoutShipmentForDebtEmailQuery)
                                                    .Union <CounterpartyEmail>(errorSendedOrderWithoutShipmentForAdvancePaymentEmailQuery)
                                                    .Union <CounterpartyEmail>(errorSendedOrderWithoutShipmentForPaymentEmailQuery);

                var errorSendedCounterpartyEmailsList = errorSendedCounterpartyEmails.ToList();

                foreach (var sendedEmail in errorSendedCounterpartyEmailsList)
                {
                    try
                    {
                        using (var unitOfWork = UnitOfWorkFactory.CreateWithoutRoot("StoredEmail"))
                        {
                            var storedEmail = new StoredEmail
                            {
                                State            = StoredEmailStates.PreparingToSend,
                                Author           = sendedEmail.StoredEmail.Author,
                                ManualSending    = true,
                                SendDate         = DateTime.Now,
                                StateChangeDate  = DateTime.Now,
                                Subject          = sendedEmail.StoredEmail.Subject,
                                RecipientAddress = sendedEmail.StoredEmail.RecipientAddress
                            };

                            unitOfWork.Save(storedEmail);

                            switch (sendedEmail.Type)
                            {
                            case CounterpartyEmailType.OrderDocument:
                                var orderDocumentEmail = new OrderDocumentEmail
                                {
                                    StoredEmail   = storedEmail,
                                    Counterparty  = sendedEmail.Counterparty,
                                    OrderDocument = ((OrderDocumentEmail)sendedEmail).OrderDocument
                                };

                                unitOfWork.Save(orderDocumentEmail);

                                break;

                            case CounterpartyEmailType.OrderWithoutShipmentForDebt:
                                var orderWithoutShipmentForDebtEmail = new OrderWithoutShipmentForDebtEmail()
                                {
                                    StoredEmail  = storedEmail,
                                    Counterparty = sendedEmail.Counterparty,
                                    OrderWithoutShipmentForDebt = (OrderWithoutShipmentForDebt)sendedEmail.EmailableDocument
                                };

                                unitOfWork.Save(orderWithoutShipmentForDebtEmail);

                                break;

                            case CounterpartyEmailType.OrderWithoutShipmentForAdvancePayment:
                                var orderWithoutShipmentForAdvancePaymentEmail = new OrderWithoutShipmentForAdvancePaymentEmail()
                                {
                                    StoredEmail  = storedEmail,
                                    Counterparty = sendedEmail.Counterparty,
                                    OrderWithoutShipmentForAdvancePayment = (OrderWithoutShipmentForAdvancePayment)sendedEmail.EmailableDocument
                                };

                                unitOfWork.Save(orderWithoutShipmentForAdvancePaymentEmail);

                                break;

                            case CounterpartyEmailType.OrderWithoutShipmentForPayment:
                                var orderWithoutShipmentForPaymentEmail = new OrderWithoutShipmentForPaymentEmail()
                                {
                                    StoredEmail  = storedEmail,
                                    Counterparty = sendedEmail.Counterparty,
                                    OrderWithoutShipmentForPayment = (OrderWithoutShipmentForPayment)sendedEmail.EmailableDocument
                                };

                                unitOfWork.Save(orderWithoutShipmentForPaymentEmail);

                                break;
                            }

                            unitOfWork.Commit();
                        }
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine($"Ошибка отправки { sendedEmail.Id } : { e.Message }");
                    }
                }
            }
        }
 public NewOrderEventArgs(OrderDocument orderDocument)
 {
     OrderDocument = orderDocument;
 }