public void Execute(AddInvoiceLineItemCommand 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.ValueLineItem; lineItem.Vat = command.LineItemVatValue; lineItem.ProductDiscount = command.LineItemProductDiscount; lineItem.OrderLineItemType = command.LineItemType; 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("AddInvoiceLineItemCommandHandler exception", ex); throw ; } }
private static void CheckAddInvoiceLineItemCommand(ProductLineItem item, AddInvoiceLineItemCommand command) { Assert.AreEqual(item.Product.Id, command.ProductId, "Line item Product ID"); Assert.AreEqual(item.Quantity, command.Qty, "Line item quantity"); Assert.AreEqual(item.Value, command.ValueLineItem, "Line item value"); Assert.AreEqual(item.VatValue, command.LineItemVatValue, "Line item VAT value"); }