public void Execute(AddDispatchNoteLineItemCommand command)
        {
             _log.InfoFormat("Execute {1} - Command Id {0} ", command.CommandId, command.GetType().ToString());

             try
             {
                 if (!DocumentExists(command.DocumentId))
                 {
                     _log.InfoFormat("Cannot add line item. Document does not exist  Execute {1} - Command Id {0} ", command.CommandId, command.GetType());
                     return;
                 }
                 if (DocumentLineItemExists(command.CommandId))
                 {
                     _log.InfoFormat("Cannot add line item {0}. Line item already exists", command.CommandId);
                     return;
                 }

                 tblDocument doc = ExistingDocument(command.DocumentId);
                 tblLineItems lineItem = NewLineItem(command.CommandId, command.DocumentId, command.ProductId,
                                                    command.Description, command.Qty, command.LineItemSequenceNo);
                 lineItem.Value = command.Value;
                 lineItem.Vat = command.LineItemVatValue;
                 lineItem.OrderLineItemType = command.LineItemType;
                 lineItem.ProductDiscount = command.LineItemProductDiscount;
                 lineItem.DiscountLineItemTypeId = command.DiscountType;

                 doc.tblLineItems.Add(lineItem);
                 _cokeDataContext.SaveChanges();
             }
             catch (Exception ex)
             {
                 _log.ErrorFormat("Error Execute {1} - Command Id {0} ", command.CommandId, command.GetType().ToString());
                 //_log.Error(ex);
                 throw ;
             }
        }
        List<CommandRouteItem> GetAddDispatchNoteLineItemCommandRoutes(AddDispatchNoteLineItemCommand addDispatchNoteLineItemCommand)
        {
            List<CommandRouteItem> commandRouteItems = new List<CommandRouteItem>();
            string serializedCommand = JsonConvert.SerializeObject(addDispatchNoteLineItemCommand);

            List<Guid> ids = GetDestinationIdsFromDispatchNoteId(addDispatchNoteLineItemCommand.DocumentId);

            Guid[] _destinationIds = RemoveSourceCCAppId(ids.ToArray(), addDispatchNoteLineItemCommand);

            foreach (Guid id in _destinationIds)
                commandRouteItems.Add(CreateRouteItem(addDispatchNoteLineItemCommand, "AddDispatchNoteLineItem", id, serializedCommand));
            return commandRouteItems;
        }
 public void Handle(AddDispatchNoteLineItemCommand command)
 {
     if (currentDispatchNoteType != 2) return;
     
     var order = GetOrder();
     if (order != null)
     {
         var item = order.ReturnableLineItems.Find(r => r.ProductMasterId == command.ProductId && r.Quantity == command.Qty);
         if (item == null) return;
         item.SaleQuantity = command.Qty;
         item.LineItemStatus = LineItemStatus.Approved;
     }
 }