public void AddTransaction(dtoTransaction t, int userId) { var transaction = new tbl_transaction { documentId = t.documentId, productId = t.productId, transactionType = t.transactionType, quantity = t.quantity, unitPrice = t.unitPrice, dateCreated = DateTime.Now, discountA = t.discountA ?? 0, discountB = t.discountB ?? 0, discountC = t.discountC ?? 0, }; var product = DBContext.tbl_product.FirstOrDefault(d => d.productId == t.productId); if (product != null) { if (t.transactionType == 1) { if (t.unitPrice > 0) { var priceHistory = new tbl_productPriceHistory() { productId = product.productId, dateCreated = DateTime.Now, createdBy = userId, price = product.unitPrice }; DBContext.tbl_productPriceHistory.Add(priceHistory); product.unitPrice = t.unitPrice; } product.incoming = product.incoming + t.quantity; product.ending = (product.beginning + product.incoming) - product.outgoing; } else if (t.transactionType == 6) { //product.unitPrice = t.unitPrice; product.outgoing = product.outgoing + t.quantity; product.ending = (product.beginning + product.incoming) - product.outgoing; } } DBContext.tbl_transaction.Add(transaction); t.transactionId = transaction.transactionId; }
public void AddTransaction(dtoTransaction t) { var transaction = new tbl_transaction { documentId = t.documentId, productId = t.productId, transactionType = t.transactionType, quantity = t.quantity, unitPrice = t.unitPrice, dateCreated = DateTime.Now, discountA = t.discountA ?? 0, discountB = t.discountB ?? 0, discountC = t.discountC ?? 0, }; if (t.transactionType == 1) { var product = DBContext.tbl_product.FirstOrDefault(d => d.productId == t.productId); product.unitPrice = t.unitPrice; } DBContext.tbl_transaction.Add(transaction); t.transactionId = transaction.transactionId; }