public async Task <ResponseModel <PaymentDto> > Handle(InitiatePaymentProcess request, CancellationToken cancellationToken) { var ResponseModel = new ResponseModel <PaymentDto>(); var item = await _dbcheapcontext.Payments.FirstOrDefaultAsync(x => x.Amount == request.Amount); var expensive = await _dbexpensivecontext.Payments.FirstOrDefaultAsync(x => x.Amount == request.Amount); var premium = await _dbpremiumcontext.Payments.FirstOrDefaultAsync(x => x.Amount == request.Amount); if (item == null || expensive == null || premium == null) { var payment = new Payments() { Id = request.Id, CreditCardNumber = request.CreditCardNumber, CardHolder = request.CardHolder, Amount = request.Amount, ExpirationDate = request.ExpirationDate }; if (request.Amount < 21) { _dbcheapcontext.Payments.Add(payment); } if (request.Amount > 21 || request.Amount < 500) { _dbexpensivecontext.Payments.Add(payment); } if (request.Amount > 500) { _dbpremiumcontext.Payments.Add(payment); } await _dbcheapcontext.SaveChangesAsync(); await _dbexpensivecontext.SaveChangesAsync(); await _dbpremiumcontext.SaveChangesAsync(); ResponseModel.IsSuccessResponse = true; ResponseModel.Message = "Payment is Processed"; ResponseModel.ResponseCode = (int)PaymentEnum.Processed; ResponseModel.Result = new PaymentDto() { Id = request.Id, CardHolder = request.CardHolder, CreditCardNumber = request.CreditCardNumber, Amount = request.Amount, SecurityCode = request.SecurityCode, ExpirationDate = request.ExpirationDate }; return(ResponseModel); } else { ResponseModel.Result = null; ResponseModel.IsSuccessResponse = false; ResponseModel.Message = "Request is Invalid"; ResponseModel.ResponseCode = (int)PaymentEnum.Failed; } return(ResponseModel); }