Given 2 tables PaymentServices
and PaymentTransaction
, the requirement is, for each payment services they can set counter start from what number. So in PaymentServices
table I added column Counter
. So user can set minimum counter to start. EG 5000
.
So every transaction created it will count to 5001
, 5002
and etc then store the value in column ReceiptNo
in table PaymentTransaction
So in my case, I can't use auto generate ID from database.
Here is the code:
var getPaymentServices = _context.PaymentServices.First(c=>c.Id == SelectedPaymentServiceId);
// Create new transaction and get current counter
var addNewPayment = new PaymentTransaction
{
PaymentServiceId = getPaymentServices.Id,
Amount = AmountToPay,
ReceiptNo = getPaymentServices.Counter,
};
getPaymentServices.Counter++;
_context.Add(addNewPayment);
await _context.SaveChangesAsync;
My QA found, some of the transaction got duplicate ReceiptNo
after do load test (around 50000 request). Even no to much but, it will impact the customer billing system.
What the best way to manage this?