public async Task Cleanup() { CoreUnitOfWork.ClearTracker(); Wallet wallet = await CoreUnitOfWork.WalletRepository.GetFirstOrDefaultWithIncludes( wallet => wallet.JMBG == "1203977780011", wallet => wallet.Transactions ); if (wallet != null) { await CoreUnitOfWork.WalletRepository.Delete(wallet); await CoreUnitOfWork.SaveChangesAsync(); } Wallet wallet2 = await CoreUnitOfWork.WalletRepository.GetFirstOrDefaultWithIncludes( wallet => wallet.JMBG == "1203008780011", wallet => wallet.Transactions ); if (wallet2 != null) { await CoreUnitOfWork.WalletRepository.Delete(wallet); await CoreUnitOfWork.SaveChangesAsync(); } await DbContext.DisposeAsync(); DbContext = null; }
public async Task Cleanup() { CoreUnitOfWork.ClearTracker(); Wallet wallet1 = await CoreUnitOfWork.WalletRepository.GetFirstOrDefaultWithIncludes( wallet => wallet.JMBG == "2904992785075", wallet => wallet.Transactions ); if (wallet1 != null) { await CoreUnitOfWork.WalletRepository.Delete(wallet1); await CoreUnitOfWork.SaveChangesAsync(); } Wallet wallet2 = await CoreUnitOfWork.WalletRepository.GetFirstOrDefaultWithIncludes( wallet => wallet.JMBG == "2904990785034", wallet => wallet.Transactions ); if (wallet2 != null) { await CoreUnitOfWork.WalletRepository.Delete(wallet2); await CoreUnitOfWork.SaveChangesAsync(); } await DbContext.DisposeAsync(); DbContext = null; }
public async Task <WalletInfoDTO> GetWalletInfo(string jmbg, string password) { Wallet wallet = await CoreUnitOfWork.WalletRepository.GetFirstOrDefaultWithIncludes( wallet => wallet.Jmbg == jmbg, wallet => wallet.Transactions ); if (wallet == null || !wallet.CheckPassword(password)) { throw new ArgumentException($"No wallet for entered jmbg '{jmbg}' and password pair."); } wallet.CheckAndUpdateUsedDepositWithdraw(); await CoreUnitOfWork.WalletRepository.Update(wallet); await CoreUnitOfWork.SaveChangesAsync(); decimal maximalDeposit; decimal maximalWithdraw; bool success = decimal.TryParse(Configuration["MaximalDeposit"], NumberStyles.AllowLeadingWhite | NumberStyles.AllowTrailingWhite | NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out maximalDeposit); if (!success) { throw new ArgumentException($"Couldn't cast {Configuration["MaximalDeposit"]} (MaximalDeposit) to decimal"); } success = decimal.TryParse(Configuration["MaximalWithdraw"], NumberStyles.AllowLeadingWhite | NumberStyles.AllowTrailingWhite | NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out maximalWithdraw); if (!success) { throw new ArgumentException($"Couldn't cast {Configuration["MaximalWithdraw"]} (MaximalWithdraw) to decimal"); } var walletInfoDTO = new WalletInfoDTO() { Jmbg = wallet.Jmbg, FirstName = wallet.FirstName, LastName = wallet.LastName, BankType = (short)wallet.BankType, BankAccount = wallet.BankAccount, Balance = wallet.Balance, UsedDepositThisMonth = wallet.UsedDepositThisMonth, MaximalDeposit = maximalDeposit, UsedWithdrawThisMonth = wallet.UsedWithdrawThisMonth, MaximalWithdraw = maximalWithdraw, IsBlocked = wallet.IsBlocked, TransactionDTOs = wallet.Transactions.Select( transaction => new TransactionDTO() { Amount = transaction.Amount, Destination = transaction.Destination, Source = transaction.Source, TransactionDateTime = transaction.TransactionDateTime, Type = (short)transaction.Type, WalletBalance = transaction.WalletBalance } ).ToList() }; return(walletInfoDTO); }
/// <summary> /// Metoda koja pravi wallet /// </summary> /// <param name="walletDTO"></param> /// <returns>Id</returns> public async Task <WalletDTO> CreateWallet(WalletDTO walletDTO) { var result = await UnitOfWork.WalletRepository.GetFirstOrDefaultWithIncludes(m => m.JMBG == walletDTO.JMBG); if (result != null) { throw new WalletServiceException("Novcanik sa ovim JMBG-om vec postoji!", "CreateWallet: Duplicate JMBG"); } bool isValid = await BankService.CheckStatus(walletDTO.JMBG, walletDTO.PIN); if (!isValid) { new WalletServiceException("PIN nije validan!", "CreateWallet: Invalid PIN"); } string pass = PassService.GeneratePASS(); Wallet newWallet = new Wallet(walletDTO.FirstName, walletDTO.LastName, walletDTO.JMBG, walletDTO.Bank, walletDTO.PIN, walletDTO.BankAccount, pass); await UnitOfWork.WalletRepository.Insert(newWallet); await UnitOfWork.SaveChangesAsync(); return(new WalletDTO(newWallet)); }
public async Task Cleanup() { CoreUnitOfWork.ClearTracking(); Wallet wallet = await CoreUnitOfWork.WalletRepository.GetFirstOrDefaultWithIncludes( wallet => wallet.Jmbg == "0605996781029", wallet => wallet.Transactions ); if (wallet != null) { await CoreUnitOfWork.WalletRepository.Delete(wallet); await CoreUnitOfWork.SaveChangesAsync(); } await DbContext.DisposeAsync(); DbContext = null; }
public async Task <UserAccountDto> CreateUser(string firstName, string lastName, string userIdentificationNumber, BankType bankType, string bankAccountNumber, int bankPin) { var userAccount = await _coreUnitOfWork.UserAccountRepository.GetFirstOrDefaultWithIncludes(userAcc => userAcc.IdentificationNumber == userIdentificationNumber.Trim()); if (userAccount != null) { throw new NotValidActionException($"User account with user identity: { userIdentificationNumber } already exists."); } if (!UserIdentificationValidationHelper.MaturityValidateIdentificationNumber(userIdentificationNumber)) { throw new NotValidParameterException("identification number not valid"); } var newPassword = await _bankService.ValidateUserBankAccountAndGeneratePassword(userIdentificationNumber, bankAccountNumber, bankPin); UserAccount u = new UserAccount(firstName, lastName, userIdentificationNumber, bankType, bankAccountNumber, newPassword, false); await _coreUnitOfWork.UserAccountRepository.Insert(u); await _coreUnitOfWork.SaveChangesAsync(); return(u.ToDto()); }
public async Task Cleanup() { CoreUnitOfWork.ClearTracking(); Wallet wallet = await CoreUnitOfWork.WalletRepository.GetById("0605996781029"); if (wallet != null) { await CoreUnitOfWork.WalletRepository.Delete(wallet); await CoreUnitOfWork.SaveChangesAsync(); } await DbContext.DisposeAsync(); DbContext = null; }
public async Task <string> CreateWallet( string jmbg, string firstName, string lastName, short bankType, string bankAccountNumber, string bankPIN ) { if (string.IsNullOrEmpty(jmbg)) { throw new ArgumentNullException($"{nameof(jmbg)}"); } Wallet existingWallet = await CoreUnitOfWork.WalletRepository.GetById(jmbg); if (existingWallet != null) { throw new InvalidOperationException($"Wallet with JMBG = {jmbg} already exists"); } //provera ka servisu banke da li uopste moze da se kreira wallet var response = await BankRoutingService.CheckStatus(jmbg, bankPIN, (BankType)bankType); if (!response.IsSuccess) { throw new InvalidOperationException($"Creating wallet for JMBG= {jmbg} and PIN= {bankPIN} not allowed"); } //provera da li je korisnik punoletan if (JMBGParser.CalculatePersonsYearsFromJMBG(jmbg) < 18) { throw new InvalidOperationException($"Creating wallet for JMBG= {jmbg} and PIN= {bankPIN} not allowed because person is under 18"); } string pass = Guid.NewGuid().ToString().Substring(0, 6); Wallet wallet = new Wallet(jmbg, firstName, lastName, (BankType)bankType, bankAccountNumber, bankPIN, pass); await CoreUnitOfWork.WalletRepository.Insert(wallet); await CoreUnitOfWork.SaveChangesAsync(); return(pass); }