Exemplo n.º 1
0
        public async Task <WalletDto> GetWalletById(long id)
        {
            try
            {
                var model = await _weGOPAYDbContext.Wallet.Where(a => a.Id == id).FirstOrDefaultAsync();

                if (model == null)
                {
                    return(null);
                }
                var nAcct = new WalletDto
                {
                    Id                 = model.Id,
                    UserId             = model.UserId,
                    Status             = model.Status,
                    NairaBalance       = model.NairaBalance,
                    USDBalance         = model.USDBalance,
                    EuroBalance        = model.EuroBalance,
                    PoundBalance       = model.PoundBalance,
                    YenBalance         = model.YenBalance,
                    WalletCreationDate = model.WalletCreationDate
                };
                return(nAcct);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 2
0
        public async Task <Result> BankTransfer(WalletDto walletToUpdate)
        {
            var entity = await _context.Wallets.FirstOrDefaultAsync(x => x.Id == walletToUpdate.Id && !x.Deleted);

            if (entity == null)
            {
                return(Result.Failure(new List <string> {
                    "No valid wallet found"
                }));
            }

            if (entity.TotalAmount >= walletToUpdate.TotalAmount)
            {
                entity.TotalAmount -= walletToUpdate.TotalAmount;
            }
            else
            {
                return(Result.Failure(new List <string> {
                    "Insuficient funds"
                }));
            }


            await _context.SaveChangesAsync();

            return(Result.Success("Money were transfered successfully"));
        }
Exemplo n.º 3
0
        public IActionResult AddWallet(string accountNumber)
        {
            WalletDto walletDto = new WalletDto();

            walletDto.AccountNumber = accountNumber;
            return(View(walletDto));
        }
Exemplo n.º 4
0
        public IActionResult UpdateWallet(int id, [FromBody] WalletDto wallet)
        {
            var walletFromDb = _walletRepository.GetWalletById(id);

            if (walletFromDb == null)
            {
                return(NotFound());
            }


            walletFromDb.CurrencyCode = wallet.CurrencyCode;
            walletFromDb.CurrencyName = wallet.CurrencyName;
            walletFromDb.Description  = wallet.Description;

            if (!TryValidateModel(walletFromDb))
            {
                return(BadRequest());
            }

            _walletRepository.SaveChanges();

            var walletToReturn = _mapper.Map <WalletDto>(walletFromDb);

            return(CreatedAtRoute("GetWalletById", new { id = walletFromDb.Id }, walletToReturn));
        }
Exemplo n.º 5
0
        // write wallet info to json
        public static void WriteWalletToJson(WalletDto wallet)
        {
            DeleteFile(PathToWallet + ".aes");

            List <WalletDto> _data = new List <WalletDto>();

            _data.Add(wallet);
            string json = JsonConvert.SerializeObject(_data.ToArray());

            File.WriteAllText(PathToWallet, json);

            string password = "******";

            // For additional security Pin the password of your files
            GCHandle gch = GCHandle.Alloc(password, GCHandleType.Pinned);

            // Encrypt the file
            AESEncryptionHelper.FileEncrypt(PathToWallet, password);

            // To increase the security of the encryption, delete the given password from the memory !
            AESEncryptionHelper.ZeroMemory(gch.AddrOfPinnedObject(), password.Length * 2);
            gch.Free();

            DeleteFile(PathToWallet);
        }
Exemplo n.º 6
0
        public async Task <Result> SendMoney(WalletDto walletToUpdate)
        {
            await using var transaction = await _context.Database.BeginTransactionAsync();

            try
            {
                var beneficiaryWallet = await _context.Wallets
                                        .Where(x => x.CurrencyId == walletToUpdate.CurrencyId)
                                        .FirstOrDefaultAsync(x => x.UserId == walletToUpdate.UserId && !x.Deleted);

                var currentUserWallet = await _context.Wallets
                                        .Where(x => x.CurrencyId == walletToUpdate.CurrencyId)
                                        .FirstOrDefaultAsync(x => x.UserId == _currentUserService.UserId.Value && !x.Deleted);


                if (beneficiaryWallet == null)
                {
                    return(Result.Failure(new List <string> {
                        "No valid beneficiary wallet found"
                    }));
                }


                if (currentUserWallet.TotalAmount >= walletToUpdate.TotalAmount)
                {
                    currentUserWallet.TotalAmount -= walletToUpdate.TotalAmount;
                    beneficiaryWallet.TotalAmount += walletToUpdate.TotalAmount;

                    var entity = new TransactionHistory
                    {
                        Amount       = walletToUpdate.TotalAmount,
                        SenderId     = _currentUserService.UserId.Value,
                        BeneficiarId = beneficiaryWallet.UserId,
                        CurrencyId   = walletToUpdate.CurrencyId
                    };

                    await _context.TransactionsHistory.AddAsync(entity);
                }
                else
                {
                    return(Result.Failure(new List <string> {
                        "Insufficient funds"
                    }));
                }

                await _context.SaveChangesAsync();

                await transaction.CommitAsync();

                return(Result.Success("Transaction was successful"));
            }
            catch (Exception e)
            {
                await transaction.RollbackAsync();

                throw new Exception(e.ToString());
            }
        }
Exemplo n.º 7
0
        public static WalletDto ToWalletDto(this decimal val)
        {
            var wallet = new WalletDto();

            (val, wallet.OneEuroCoinAmount)    = val.GetCoinChange(CoinType.OneEuro);
            (val, wallet.FiftyCentCoinAmount)  = val.GetCoinChange(CoinType.FiftyCent);
            (val, wallet.TwentyCentCoinAmount) = val.GetCoinChange(CoinType.TwentyCent);
            (_, wallet.TenCentCoinAmount)      = val.GetCoinChange(CoinType.TenCent);

            return(wallet);
        }
Exemplo n.º 8
0
        public async Task <ActionResult <Result> > BankTransfer([FromBody] WalletDto walletToUpdate)
        {
            var result = await _walletService.BankTransfer(walletToUpdate);

            if (!result.Succeeded)
            {
                return(BadRequest(result));
            }

            return(Ok(result));
        }
Exemplo n.º 9
0
        public async Task <ActionResult <Result> > AddMoneyToWallet([FromBody] WalletDto walletToUpdate)
        {
            var result = await _walletService.AddMoneyToWallet(walletToUpdate);

            if (!result.Succeeded)
            {
                return(BadRequest(result));
            }

            return(Ok(result));
        }
Exemplo n.º 10
0
        public async Task <WalletDto> CreateWalletAsync(int userId, WalletDto walletDto)
        {
            await ThrowIfNameExists(userId, walletDto.Name);

            walletDto.UserId = userId;
            var walletEntity = Mapper.Map <Wallet>(walletDto);

            UnitOfWork.WalletRepository.Create(walletEntity);
            await UnitOfWork.CommitAsync();

            return(Mapper.Map <WalletDto>(walletEntity));
        }
Exemplo n.º 11
0
        public IActionResult Index()
        {
            var use = User.Identity.Name;

            var load = _custManager.GetCustomEmailwithUserSignin(use);

            WalletDto walletDto = new WalletDto();

            walletDto.AccountBalance = load.Cust_balance;
            walletDto.AccountNumber  = load.CustAccNumber;

            return(View(walletDto));
        }
Exemplo n.º 12
0
        public IActionResult AddWallet(WalletDto wallet)
        {
            /// here take it to payment gateway

            //TransferValidator bankValidator = new TransferValidator();
            //ValidationResult result = bankValidator.Validate(wallet);

            //if (!result.IsValid)
            //{
            //    return BadRequest(result.Errors);
            //}

            if (ModelState.IsValid)
            {
                var cust = _custManager.GetCustomerDetails(wallet.AccountNumber);
                var jsonRequestBehavior            = new JsonSerializerSettings();
                TransactionModel gotoPaymentDirect = new TransactionModel
                {
                    FullName   = cust.Result.Surname + " " + cust.Result.GivenName,
                    CustomerID = cust.Result.CustomerId.ToString(),
                    Amount     = wallet.Amount,
                    Savecode   = GenerateMerchantRef(),
                    Email      = cust.Result.EmailAdress,
                    Phone      = cust.Result.TelephoneNumber,
                    IsActive   = false,
                    IsDeleted  = false
                };

                var postTransction = _payment.PostTransaction(gotoPaymentDirect);
                if (postTransction.UniqueKey != null)
                {
                    return(Json(new { redirectUrl = postTransction.UniqueKey, isRedirect = true }, jsonRequestBehavior));
                }


                if (gotoPaymentDirect.Amount != 0)
                {
                    return(RedirectToAction("MakePayment", gotoPaymentDirect));
                }
                else
                {
                    return(View("MakePayment", gotoPaymentDirect));
                }
            }
            else
            {
                TempData["Error"] = "bad";
            }
            return(View(wallet));
        }
Exemplo n.º 13
0
        public async Task <SelectItemVm> GetAllAsSelect(WalletDto walletDto)
        {
            var vm = new SelectItemVm
            {
                SelectItems = await _context.Wallets
                              .Where(x => !x.Deleted)
                              .Select(x => new SelectItemDto {
                    Label = x.TotalAmount.ToString(), Value = x.Id.ToString()
                })
                              .ToListAsync()
            };

            return(vm);
        }
Exemplo n.º 14
0
        private void button1_Click(object sender, EventArgs e)
        {
            WalletView walletInfo = _moneyTransferBl.GetWalletInfoForGrid();

            textBoxBitcoinAdress.Text = walletInfo.BitcoinAdress;
            textBoxPublicKey.Text     = walletInfo.PublicKey;
            textBoxScriptPubKey.Text  = walletInfo.ScriptPubKey;

            WalletDto walletDto = new WalletDto(walletInfo.BitcoinAdress,
                                                walletInfo.PublicKey,
                                                walletInfo.ScriptPubKey);

            FileHelper.WriteWalletToJson(walletDto);
        }
Exemplo n.º 15
0
        public MainWindow()
        {
            _moneyTransferBl = new MoneyTransferBl(new Wallet(), new TransactionClient());

            InitializeComponent();
            WalletDto wallet = FileHelper.LoadWalletFromJson();

            if (wallet != null)
            {
                textBoxBitcoinAdress.Text = wallet.BitcoinAdress;
                textBoxPublicKey.Text     = wallet.PublicKey;
                textBoxScriptPubKey.Text  = wallet.ScriptPubKey;
            }
        }
Exemplo n.º 16
0
        public WalletDto CreateWallet(int userId, WalletDto walletDto)
        {
            //1. userid does not have a wallet
            //2. WalletDto - Wallet
            //3. Save Wallet to Database
            //4. Return new WalletDto
            var user = _dbContext.Users.FirstOrDefault(x => x.Id == userId);

            if (user == null)
            {
                throw new ArgumentNullException(nameof(user), $"Not found user by id {userId}");
            }
            return(walletDto);
        }
Exemplo n.º 17
0
        public async Task <Result> AddWallet(WalletDto walletToAdd)
        {
            var entity = new Wallet
            {
                TotalAmount = walletToAdd.TotalAmount,
                UserId      = walletToAdd.UserId,
                CurrencyId  = walletToAdd.CurrencyId
            };

            await _context.Wallets.AddAsync(entity);

            await _context.SaveChangesAsync();

            return(Result.Success("Wallet was created successfully"));
        }
Exemplo n.º 18
0
        public async Task <IActionResult> AddWallet([FromBody] WalletDto walletToAdd)
        {
            if (walletToAdd.CurrencyId == 0)
            {
                return(BadRequest("The currency is mandatory!"));
            }
            var result = await _walletService.AddWallet(walletToAdd);

            if (!result.Succeeded)
            {
                return(BadRequest(result));
            }

            return(Ok(result));
        }
Exemplo n.º 19
0
        public async Task <SelectItemVm> GetWalletsForCurrentUserAsSelect(WalletDto walletDto)
        {
            var vm = new SelectItemVm
            {
                SelectItems = await _context.Wallets
                              .Where(x => x.UserId == _currentUserService.UserId && !x.Deleted)
                              .Select(x => new SelectItemDto {
                    Label = x.Currency.CurrencyName + " " + x.TotalAmount.ToString(), Value = x.Id.ToString()
                })
                              .OrderByDescending(x => x.Label)
                              .ToListAsync()
            };

            return(vm);
        }
Exemplo n.º 20
0
        public IActionResult CreateWallet([FromBody] WalletDto wallet)
        {
            var walletEntity = _mapper.Map <Wallet>(wallet);

            if (!TryValidateModel(walletEntity))
            {
                return(BadRequest());
            }

            _walletRepository.AddWallet(walletEntity);

            var walletToReturn = _mapper.Map <WalletDto>(walletEntity);


            return(CreatedAtRoute("GetWalletById", new { id = walletEntity.Id }, walletToReturn));
        }
Exemplo n.º 21
0
        public async Task <Result> AddMoneyToWallet(WalletDto walletToUpdate)
        {
            var entity = await _context.Wallets.FirstOrDefaultAsync(x => x.Id == walletToUpdate.Id && !x.Deleted);

            if (entity == null)
            {
                return(Result.Failure(new List <string> {
                    "No valid wallet found"
                }));
            }

            entity.TotalAmount += walletToUpdate.TotalAmount;

            await _context.SaveChangesAsync();

            return(Result.Success("Money were added successfully"));
        }
Exemplo n.º 22
0
        public async Task <Result> DeleteWallet(WalletDto walletToDelete)
        {
            var entity = await _context.Wallets
                         .FirstOrDefaultAsync(x => x.Id == walletToDelete.Id && !x.Deleted);

            if (entity == null)
            {
                return(Result.Failure(new List <string> {
                    "No valid wallet found"
                }));
            }

            entity.Deleted = true;

            await _context.SaveChangesAsync();

            return(Result.Success("Wallet was deleted"));
        }
Exemplo n.º 23
0
        public async Task <Result> RestoreWallet(WalletDto walletToRestore)
        {
            var entity = await _context.Wallets
                         .FirstOrDefaultAsync(x => x.Id == walletToRestore.Id && x.Deleted);

            if (entity == null)
            {
                return(Result.Failure(new List <string> {
                    "No valid wallet found"
                }));
            }

            entity.Deleted   = false;
            entity.DeletedBy = null;
            entity.DeletedOn = null;

            await _context.SaveChangesAsync();

            return(Result.Success("Wallet was restored"));
        }
Exemplo n.º 24
0
        public async Task <Result> UpdateWallet(WalletDto walletToUpdate)
        {
            var entity = await _context.Wallets
                         .FirstOrDefaultAsync(x => x.Id == walletToUpdate.Id && !x.Deleted);

            if (entity == null)
            {
                return(Result.Failure(new List <string> {
                    "No valid wallet found"
                }));
            }

            entity.TotalAmount = walletToUpdate.TotalAmount;
            entity.UserId      = walletToUpdate.UserId;
            entity.CurrencyId  = walletToUpdate.CurrencyId;

            await _context.SaveChangesAsync();

            return(Result.Success("Wallet update was successful"));
        }
        public async Task <IActionResult> Trade(TradeCreateDto tradeCreateDto)
        {
            Guid      userId    = Guid.Parse(sharedIdentityService.GetUserId);
            WalletDto walletDto = await walletService.GetWalletByUserIdAsync(userId);

            var productItem = await productItemService.GetAsync(walletDto.Id, tradeCreateDto.ProductId);

            if (tradeCreateDto.TradeType == DTO.General.TradeType.Sell)
            {
                var sellDto = mapper.Map <SellModel>(tradeCreateDto);
                sellDto.ProductItem = productItem;
                sellDto.WalletId    = walletDto.Id;
                sellDto.UserId      = userId;
                var response = await tradeService.SellAsync(sellDto);

                ScannerServiceState.IsScanned = true;
                return(CreateResponseInstance(response));
            }
            else if (tradeCreateDto.TradeType == DTO.General.TradeType.Buy)
            {
                var buyDto = mapper.Map <BuyModel>(tradeCreateDto);
                buyDto.ProductItem = productItem;
                buyDto.WalletId    = walletDto.Id;
                buyDto.UserId      = userId;
                buyDto.WalletDto   = walletDto;
                var response = await tradeService.BuyAsync(buyDto);

                ScannerServiceState.IsScanned = true;
                return(CreateResponseInstance(response));
            }
            else
            {
                var buyDto = mapper.Map <BuybyLimitModel>(tradeCreateDto);
                buyDto.WalletId = walletDto.Id;
                buyDto.UserId   = userId;
                var response = await tradeService.BuybyLimitAsync(buyDto);

                ScannerServiceState.IsScanned = true;
                return(CreateResponseInstance(response));
            }
        }
Exemplo n.º 26
0
        private WalletWithAddressExtensionDto ConvertWalletToWalletWithAddressExtension(
            WalletDto walletDto)
        {
            if (walletDto == null)
            {
                return(null);
            }

            var parseAddressResult = _addressParser.ExtractAddressParts(walletDto.BlockchainType, walletDto.Address);

            return(new WalletWithAddressExtensionDto
            {
                Address = walletDto.Address,
                AddressExtension = parseAddressResult.AddressExtension,
                AssetId = walletDto.AssetId,
                BaseAddress = parseAddressResult.BaseAddress,
                BlockchainType = walletDto.BlockchainType,
                ClientId = walletDto.ClientId,
                CreatorType = walletDto.CreatorType
            });
        }
Exemplo n.º 27
0
 public static void InsertCoinsFromTestInput(
     this IVendingMachineService service,
     WalletDto wallet)
 {
     if (wallet.OneEuroCoinAmount > 0)
     {
         service.InsertCoins(CoinType.OneEuro, wallet.OneEuroCoinAmount);
     }
     if (wallet.FiftyCentCoinAmount > 0)
     {
         service.InsertCoins(CoinType.FiftyCent, wallet.FiftyCentCoinAmount);
     }
     if (wallet.TwentyCentCoinAmount > 0)
     {
         service.InsertCoins(CoinType.TwentyCent, wallet.TwentyCentCoinAmount);
     }
     if (wallet.TenCentCoinAmount > 0)
     {
         service.InsertCoins(CoinType.TenCent, wallet.TenCentCoinAmount);
     }
 }
Exemplo n.º 28
0
        public async Task <WalletDto> GetWalletByUserId(string userId)
        {
            var model = await _weGOPAYDbContext.Wallet.Where(a => a.UserId == userId).FirstOrDefaultAsync();

            if (model == null)
            {
                return(null);
            }
            var nAcct = new WalletDto
            {
                Id                 = model.Id,
                UserId             = model.UserId,
                Status             = model.Status,
                NairaBalance       = model.NairaBalance,
                USDBalance         = model.USDBalance,
                EuroBalance        = model.EuroBalance,
                PoundBalance       = model.PoundBalance,
                YenBalance         = model.YenBalance,
                WalletCreationDate = model.WalletCreationDate
            };

            return(nAcct);
        }
Exemplo n.º 29
0
        public async Task <IActionResult> ChangeWallet([FromRoute(Name = "id")] Guid walletId, [FromBody] WalletDto dto)
        {
            try
            {
                var myId = ExtractIdFromToken(Request.Headers[HttpRequestHeader.Authorization.ToString()]);

                return(Ok(await service.ChangeWallet(myId,
                                                     walletId,
                                                     dto,
                                                     IsAdmin(Request.Headers[HttpRequestHeader.Authorization.ToString()]))));
            }
            catch (HttpResponseException)
            {
                throw;
            }
            catch (Exception)
            {
                throw new BadRequestApiException();
            }
        }
Exemplo n.º 30
0
        public async Task <QueryResults <WalletDto> > ChangeWallet(Guid me, Guid walletId, WalletDto walletDto, bool isAdmin)
        {
            var wallet = await db.Wallets.Include(w => w.OfUser)
                         .ThenInclude(u => u.AsRenter)
                         .ThenInclude(l => l.Garden)
                         .ThenInclude(g => g.Criteria)
                         .GetByIdAsync(walletId) ?? throw new NotFoundApiException();

            if (!wallet.OfUser.Id.Equals(me) && !isAdmin)
            {
                throw new ForbiddenApiException();
            }

            wallet.TrueBalance += walletDto.Balance;
            await db.SaveChangesAsync();

            return(new QueryResults <WalletDto>
            {
                Data = wallet.ConvertToDto()
            });
        }