//MessedUp Code...Logic shouldnt have write actions to database public async Task <Transaction> AddSalesTransactionAsync(Transaction model, string agentId) { Transaction TransactionRecord = model; Batch Batch = BatchRepo.Get(c => c.Id == model.BatchId); Product Product = Batch.Product; if (TransactionRecord.BulkPurchase) { TransactionRecord.Quantity *= Product.QuantityPerCarton; TransactionRecord.TotalCost = TransactionRecord.Quantity * Batch.SellingPrice * ((100 - Product.BulkPurchaseDiscountPercent) / 100); } else { TransactionRecord.TotalCost = TransactionRecord.Quantity * Batch.SellingPrice; } TransactionRecord.AgentId = agentId; TransactionRecord.TransactionType = TransactionType.Sale; Batch.QuantitySold += TransactionRecord.Quantity; await BatchRepo.UpdateAsync(Batch); return(await TransactionRepo.AddAsync(TransactionRecord)); }