public Task <GetListAccountResponse> GetListAccount() { var response = new GetListAccountResponse(); try { var listAccount = (from p in _context.WalletType join c in _context.Wallets on p.WalletTypeId equals c.WalletTypeId select new { AccountType = p.WalletTypeName, Balance = c.Balance, }).ToListAsync().Result; foreach (var account in listAccount) { var acountItem = new AcountItem() { AccountType = account.AccountType, Balance = account.Balance }; response.Data.ListAccount.Add(acountItem); } } catch (Exception ex) { response.Code = ErrorCode.GetError(ErrorCode.SystemError).Key; response.Message = ErrorCode.GetError(ErrorCode.SystemError).Value; Logger.Error(ex); } return(Task.FromResult(response)); }
public Task <GetTransactionDetailResponse> GetTransactionDetail(GetTransactionDetailRequest request) { var response = new GetTransactionDetailResponse(); try { var transactionDetail = (from p in _context.Transactions join c in _context.TransactionType on p.TransactionTypeId equals c.TransactionTypeId where p.TransactionId == request.TransactionId select new { TransactionType = c.TransactionTypeName, Amount = p.Amount, TransactionDate = p.TransDate, Status = p.Status, TransactionId = p.TransactionId, }).FirstOrDefault(); response.Data.Amount = transactionDetail.Amount; response.Data.TransactionType = transactionDetail.TransactionType; response.Data.TransactionDate = transactionDetail.TransactionDate; response.Data.Status = transactionDetail.Status; response.Data.TransactionId = transactionDetail.TransactionId; } catch (Exception ex) { response.Code = ErrorCode.GetError(ErrorCode.SystemError).Key; response.Message = ErrorCode.GetError(ErrorCode.SystemError).Value; Logger.Error(ex); } return(Task.FromResult(response)); }
public async Task <GetListTransactionResponse> GetListTransactionAsync() { var response = new GetListTransactionResponse(); try { var listTransaction = await _context.Transactions.Take(20).OrderByDescending(t => t.TransDate).ToListAsync(); foreach (var transaction in listTransaction) { var acountItem = new ItemTransaction() { TransType = transaction.TransType, Amount = transaction.Amount, TransactionDate = transaction.TransDate, Status = transaction.Status, Fee = transaction.Fee }; response.Data.ListTransaction.Add(acountItem); } } catch (Exception ex) { response.Code = ErrorCode.GetError(ErrorCode.SystemError).Key; response.Message = ErrorCode.GetError(ErrorCode.SystemError).Value; Logger.Error(ex); } return(await Task.FromResult(response)); }
public Task <GetBalanceResponse> GetBalance(GetBalanceRequest request) { var response = new GetBalanceResponse(); try { var wallet = (from p in _context.WalletType join c in _context.Wallets on p.WalletTypeId equals c.WalletTypeId where p.WalletTypeName == request.AccountType select new { Balance = c.Balance, }).FirstOrDefault(); response.Data.Balance = wallet.Balance; } catch (Exception ex) { response.Code = ErrorCode.GetError(ErrorCode.SystemError).Key; response.Message = ErrorCode.GetError(ErrorCode.SystemError).Value; Logger.Error(ex); } return(Task.FromResult(response)); }
public async Task <IActionResult> withdraw([FromBody] WithdrawCommand command) { var response = new DepositResponse(); try { if (command.Amount < 50000 || command.Amount % 50000 != 0) { response.Code = ErrorCode.GetError(ErrorCode.AmountInvalid).Key; response.Message = ErrorCode.GetError(ErrorCode.AmountInvalid).Value; return(Ok(response)); } var walletType = _context.WalletType.Where(s => s.WalletTypeName == WalletTypeEnum.CHECKING.ToString()).FirstOrDefault(); var transactionType = _context.TransactionType.Where(s => s.TransactionTypeName == TransactionTypeEnum.WITHDRAW.ToString()).FirstOrDefault(); command.Fee = transactionType.Fee; command.TransactionTypeId = transactionType.TransactionTypeId; command.WalletTypeId = walletType.WalletTypeId; response = await _mediator.Send(command); } catch (Exception ex) { response.Code = ErrorCode.GetError(ErrorCode.SystemError).Key; response.Message = ErrorCode.GetError(ErrorCode.SystemError).Value; Logger.Error($"Exception: {ex} , Method:withdraw"); } return(Ok(response)); }
public async Task <DepositResponse> Handle(DepositCommand command, CancellationToken cancellationToken) { var response = new DepositResponse(); using (var trans = _context.Database.BeginTransaction()) { try { var wallet = _context.Wallets.Where (s => s.WalletTypeId == command.WalletTypeId) .FirstOrDefault(); decimal BalanceBefore = wallet.Balance; DateTime TransDate = DateTime.Now; if (wallet != null) { wallet.Balance = wallet.Balance + command.Amount; } await _context.SaveChangesAsync(); Transaction transaction = new Transaction { Amount = command.Amount, Status = TransactionStatusEnum.SUCCESS.ToString(), TransDate = TransDate, TransactionTypeId = command.TransactionTypeId, WalletDesId = wallet.WalletId, TransType = TransactionTypeEnum.DEPOSIT.ToString(), Fee = command.Fee }; _context.Transactions.Add(transaction); await _context.SaveChangesAsync(); TransactionLog transactionLog = new TransactionLog() { AccountId = wallet.AccountId, BalanceAfter = wallet.Balance, BalanceBefore = BalanceBefore, Status = TransactionStatusEnum.SUCCESS.ToString(), TransactionDate = TransDate, TransactionId = transaction.TransactionId, TransactionTypeId = transaction.TransactionTypeId, }; _context.TransactionLogs.Add(transactionLog); await _context.SaveChangesAsync(); trans.Commit(); response.Data.Balance = wallet.Balance; response.Data.TransactionId = transaction.TransactionId; } catch (Exception ex) { trans.Rollback(); response.Code = ErrorCode.GetError(ErrorCode.SystemError).Key; response.Message = ErrorCode.GetError(ErrorCode.SystemError).Value; Logger.Error(ex); } } return(await Task.FromResult(response)); }
public async Task <IActionResult> transfer([FromBody] TransferCommand command) { var response = new BaseResponse(); try { var walletDes = (from p in _context.WalletType join c in _context.Wallets on p.WalletTypeId equals c.WalletTypeId where p.WalletTypeName == command.AccountDes select new { WalletId = c.WalletId, WalletType = p.WalletTypeName }).FirstOrDefault(); var walletSource = (from p in _context.WalletType join c in _context.Wallets on p.WalletTypeId equals c.WalletTypeId where p.WalletTypeName == command.AccountSource select new { WalletId = c.WalletId, WalletType = p.WalletTypeName, Balance = c.Balance }).FirstOrDefault(); if (walletSource == null || walletDes == null) { response.Code = ErrorCode.GetError(ErrorCode.AccountNotFound).Key; response.Message = ErrorCode.GetError(ErrorCode.AccountNotFound).Value; return(Ok(response)); } var transactionType = _context.TransactionType.Where(s => s.TransactionTypeName == TransactionTypeEnum.TRANSFER.ToString()).FirstOrDefault(); if (command.Amount + transactionType.Fee > walletSource.Balance) { response.Code = ErrorCode.GetError(ErrorCode.AmountNotEnough).Key; response.Message = ErrorCode.GetError(ErrorCode.AmountNotEnough).Value; return(Ok(response)); } command.Fee = transactionType.Fee; command.TransactionTypeId = transactionType.TransactionTypeId; command.WalletSourceId = walletSource.WalletId; command.WalletDesId = walletDes.WalletId; response = await _mediator.Send(command); } catch (Exception ex) { response.Code = ErrorCode.GetError(ErrorCode.SystemError).Key; response.Message = ErrorCode.GetError(ErrorCode.SystemError).Value; Logger.Error($"Exception: {ex} , Method:transfer"); } return(Ok(response)); }
public async Task <IActionResult> login([FromBody] LoginCommand command) { var response = new LoginResponse(); try { var traceLogin = _context.TraceLogin.LastOrDefault(); if (traceLogin != null) { if (traceLogin.CountLoginFail == 3) { response.Code = ErrorCode.GetError(ErrorCode.AccountLocked).Key; response.Message = ErrorCode.GetError(ErrorCode.AccountLocked).Value; return(Ok(response)); } } response = await _mediator.Send(command); if (response.Code == 0) { var claims = new[] { new Claim(JwtRegisteredClaimNames.Sub, command.PinCode), new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()), new Claim(JwtRegisteredClaimNames.Sub, command.PinCode) }; var symmetricSecurityKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_configuration["JwtSecurityToken:Key"])); var signingCredentials = new SigningCredentials(symmetricSecurityKey, SecurityAlgorithms.HmacSha256); var jwtSecurityToken = new JwtSecurityToken( issuer: _configuration["JwtSecurityToken:Issuer"], audience: _configuration["JwtSecurityToken:Audience"], claims: claims, expires: DateTime.UtcNow.AddMinutes(30), signingCredentials: signingCredentials ); var token = new JwtSecurityTokenHandler().WriteToken(jwtSecurityToken); var expiration = jwtSecurityToken.ValidTo; response.Data.AccessToken = token; } } catch (Exception ex) { response.Code = ErrorCode.GetError(ErrorCode.SystemError).Key; response.Message = ErrorCode.GetError(ErrorCode.SystemError).Value; Logger.Error($"Exception: {ex} , Method:login"); } return(Ok(response)); }
public Task <LoginResponse> Handle(LoginCommand command, CancellationToken cancellationToken) { var response = new LoginResponse(); try { var account = _context.Accounts .Where(s => s.PinCode == command.PinCode) .FirstOrDefault(); if (account != null) { var traceLogin = new TraceLogin { AccountId = account.AccountId, CountLoginFail = 0, IsLoginSuccess = true, TimeLogin = DateTime.Now }; _context.TraceLogin.Add(traceLogin); _context.SaveChangesAsync(); response.Data.AccountName = account.AccountName; } else { var traceLogin = _context.TraceLogin.LastOrDefault(); if (traceLogin != null) { traceLogin.CountLoginFail = traceLogin.CountLoginFail + 1; if (traceLogin.CountLoginFail == 3) { account = _context.Accounts.FirstOrDefault(); account.isLock = true; } _context.SaveChangesAsync(); } response.Code = ErrorCode.GetError(ErrorCode.PinWrong).Key; response.Message = ErrorCode.GetError(ErrorCode.PinWrong).Value; } } catch (Exception ex) { response.Code = ErrorCode.GetError(ErrorCode.SystemError).Key; response.Message = ErrorCode.GetError(ErrorCode.SystemError).Value; Logger.Error(ex); } return(Task.FromResult(response)); }
public async Task <IActionResult> GetBalance(GetBalanceRequest request) { var response = new GetBalanceResponse(); try { response = await _accountQueries.GetBalance(request); } catch (Exception ex) { response.Code = ErrorCode.GetError(ErrorCode.SystemError).Key; response.Message = ErrorCode.GetError(ErrorCode.SystemError).Value; Logger.Error($"Exception: {ex} , Method:GetBalance"); } return(Ok(response)); }
public async Task <IActionResult> GetListTransaction() { var response = new GetListTransactionResponse(); try { response = await _accountQueries.GetListTransactionAsync(); } catch (Exception ex) { response.Code = ErrorCode.GetError(ErrorCode.SystemError).Key; response.Message = ErrorCode.GetError(ErrorCode.SystemError).Value; Logger.Error($"Exception: {ex} , Method:getListtransaction"); } return(Ok(response)); }
public static void Handler(IMessage msg) { Debug.Log(msg); m_login_toc toc = msg as m_login_toc; Debug.Log(toc); if (toc.Errcode != 0) { logError(ErrorCode.GetError(toc.Errcode)); return; } if (toc.Op == (int)STATUS.REG) { BtnToLogin(); } else { GameObject.Find("Root/Login").gameObject.SetActive(false); MapSc.SetActive(true); Game.Instance.Status = GameStatus.Game; } }
public async Task <IActionResult> WithDraw(WithdrawModel model) { ErrorViewModel err = new ErrorViewModel(); try { if (ModelState.IsValid) { if (model.Amount < 50000 || model.Amount % 50000 != 0) { err.Message = ErrorCode.GetError(ErrorCode.AmountInvalid).Value; } else { var transferResponse = await _clientService.PostAsync <TransferResponse>(URLDefine.withdraw, model); if (transferResponse.Code == 0) { return(RedirectToAction("TransactionDetail", "Transaction", new { TransactionId = transferResponse.Data.TransactionId })); } else { err.Message = transferResponse.Message; } } } else { return(View()); } } catch (Exception ex) { Logger.Error($"Exception: {ex} , Method:WithDraw"); err.Message = "Lỗi hệ thống"; } return(PartialView("Error", err)); }
public async Task <WithdrawResponse> Handle(WithdrawCommand command, CancellationToken cancellationToken) { var response = new WithdrawResponse(); using (var trans = _context.Database.BeginTransaction()) { try { // hạn mức tối đa 5.000.000 if (command.Amount > 5000000) { response.Code = ErrorCode.GetError(ErrorCode.OutRange).Key; response.Message = ErrorCode.GetError(ErrorCode.OutRange).Value; return(await Task.FromResult(response)); } var wallet = _context.Wallets.Where (s => s.WalletTypeId == command.WalletTypeId) .FirstOrDefault(); // trong tk còn ít nhất 50.000 if (wallet.Balance < command.Amount - 50000 - command.Fee) { response.Code = ErrorCode.GetError(ErrorCode.AmountNotEnough).Key; response.Message = ErrorCode.GetError(ErrorCode.AmountNotEnough).Value; return(await Task.FromResult(response)); } decimal BalanceBefore = wallet.Balance; DateTime TransDate = DateTime.Now; if (wallet != null) { wallet.Balance = wallet.Balance - command.Amount - command.Fee; } await _context.SaveChangesAsync(); Transaction transaction = new Transaction { Amount = command.Amount, Status = TransactionStatusEnum.SUCCESS.ToString(), TransDate = TransDate, TransactionTypeId = command.TransactionTypeId, WalletDesId = wallet.WalletId, TransType = TransactionTypeEnum.WITHDRAW.ToString(), Fee = command.Fee }; _context.Transactions.Add(transaction); await _context.SaveChangesAsync(); TransactionLog transactionLog = new TransactionLog() { AccountId = wallet.AccountId, BalanceAfter = wallet.Balance, BalanceBefore = BalanceBefore, Status = TransactionStatusEnum.SUCCESS.ToString(), TransactionDate = TransDate, TransactionId = transaction.TransactionId, TransactionTypeId = transaction.TransactionTypeId }; _context.TransactionLogs.Add(transactionLog); await _context.SaveChangesAsync(); trans.Commit(); response.Data.Balance = wallet.Balance; response.Data.TransactionId = transaction.TransactionId; } catch (Exception ex) { trans.Rollback(); response.Code = ErrorCode.GetError(ErrorCode.SystemError).Key; response.Message = ErrorCode.GetError(ErrorCode.SystemError).Value; Logger.Error(ex); } } return(await Task.FromResult(response)); }
public async Task <TransferResponse> Handle(TransferCommand command, CancellationToken cancellationToken) { var response = new TransferResponse(); using (var trans = _context.Database.BeginTransaction()) { try { DateTime TransDate = DateTime.Now; var walletSource = _context.Wallets.Where (s => s.WalletId == command.WalletSourceId) .FirstOrDefault(); if (walletSource.Balance < command.Amount - 50000 - command.Fee) { response.Code = ErrorCode.GetError(ErrorCode.AmountNotEnough).Key; response.Message = ErrorCode.GetError(ErrorCode.AmountNotEnough).Value; return(await Task.FromResult(response)); } decimal BeforeBalanceSource = walletSource.Balance; if (walletSource != null) { walletSource.Balance = walletSource.Balance - command.Amount - command.Fee; } await _context.SaveChangesAsync(); var walletDes = _context.Wallets.Where (s => s.WalletId == command.WalletDesId) .FirstOrDefault(); decimal BeforeBalanceDes = walletDes.Balance; if (walletDes != null) { walletDes.Balance = walletDes.Balance + command.Amount; } await _context.SaveChangesAsync(); Transaction transaction = new Transaction { Amount = command.Amount, Status = TransactionStatusEnum.SUCCESS.ToString(), TransDate = TransDate, TransactionTypeId = command.TransactionTypeId, WalletDesId = walletDes.WalletId, WalletSourceId = walletSource.WalletId, TransType = TransactionTypeEnum.TRANSFER.ToString(), Fee = command.Fee }; _context.Transactions.Add(transaction); await _context.SaveChangesAsync(); TransactionLog transactionLogSource = new TransactionLog() { AccountId = walletSource.AccountId, BalanceAfter = walletSource.Balance, BalanceBefore = BeforeBalanceSource, Status = TransactionStatusEnum.SUCCESS.ToString(), TransactionDate = TransDate, TransactionId = transaction.TransactionId, TransactionTypeId = transaction.TransactionTypeId }; _context.TransactionLogs.Add(transactionLogSource); await _context.SaveChangesAsync(); TransactionLog transactionLogDes = new TransactionLog() { AccountId = walletSource.AccountId, BalanceAfter = walletDes.Balance, BalanceBefore = BeforeBalanceDes, Status = TransactionStatusEnum.SUCCESS.ToString(), TransactionDate = TransDate, TransactionId = transaction.TransactionId, TransactionTypeId = transaction.TransactionTypeId }; _context.TransactionLogs.Add(transactionLogDes); await _context.SaveChangesAsync(); response.Data.TransactionId = transaction.TransactionId; trans.Commit(); } catch (Exception ex) { trans.Rollback(); response.Code = ErrorCode.GetError(ErrorCode.SystemError).Key; response.Message = ErrorCode.GetError(ErrorCode.SystemError).Value; Logger.Error(ex); } } return(await Task.FromResult(response)); }