Exemple #1
0
        public async Task <UpdateWebHookResponse> UpdateWebHookAsync(UpdateWebHookViewModel model)
        {
            try
            {
                //get merchant
                var merchant = _context.MerchantAccounts.FirstOrDefault(x => x.ApiKey == model.HashCode);

                if (merchant != null)
                {
                    //update merchant webhook...
                    merchant.WebHook = model.WebHookURL;

                    _context.Entry(merchant).State = EntityState.Modified;
                    await _context.SaveChangesAsync();
                }

                return(new UpdateWebHookResponse
                {
                    Message = "Merchant Webhook updated successfully",
                    IsSuccess = true
                });
            }
            catch (Exception ex)
            {
                throw new NullReferenceException(ex.Message);
            }
        }
Exemple #2
0
        public async Task <FundAccountResponse> FundCustomerAsync(FundAccountViewModel model)
        {
            try
            {
                if (model == null)
                {
                    throw new NullReferenceException("Fund Account Model is Null");
                }

                //Amount and Acct Numb
                //check if account number already exists
                var result = _context.CustomerAccounts.FirstOrDefault(z => z.AccountNumber == model.AccountNumber);

                if (result != null) //if account exist
                {
                    //increment Balance on CustAcct..get cust by acct num
                    var balance = _context.CustomerAccounts.FirstOrDefault(x => x.CustomerAccountId == result.CustomerAccountId).Balance;
                    balance += model.Amount;

                    result.Balance = balance;

                    _context.Entry(result).State = EntityState.Modified;
                    await _context.SaveChangesAsync();

                    // _context.Update(cust.Balance);
                    //await _context.SaveChangesAsync();

                    //Enter value to Transaction table
                    var txn = new Transaction();
                    txn.Amount            = model.Amount;
                    txn.Type              = model.TransactionType;
                    txn.CustomerAccountId = result.CustomerAccountId.ToString();
                    txn.AccountNumber     = result.AccountNumber;
                    txn.CreatedOn         = DateTime.Now;

                    await _context.AddAsync(txn);

                    await _context.SaveChangesAsync();
                }
                else
                {
                    throw new NullReferenceException("Error Occurred.");
                }

                return(new FundAccountResponse
                {
                    Message = "Account funded successfully",
                    IsSuccess = true
                });
            }
            catch (Exception ex)
            {
                throw new NullReferenceException(ex.Message);
            }
        }