Esempio n. 1
0
        public async Task <long> CreateWallet(CreateWalletDto model, long idUser)
        {
            try
            {
                var user = await _weGOPAYDbContext.User.Where(s => s.Id == idUser).FirstOrDefaultAsync();

                var userId = user.UserId;

                var nWallet = new Wallet
                {
                    UserId       = userId,
                    Status       = model.Status.Description(),
                    NairaBalance = GetNairaBalance(model.Currency, model.Amount, userId),
                    EuroBalance  = GetEuroBalance(model.Currency, model.Amount, userId),
                    PoundBalance = GetPoundBalance(model.Currency, model.Amount, userId),
                    USDBalance   = GetDollarBalance(model.Currency, model.Amount, userId),
                    YenBalance   = GetYenBalance(model.Currency, model.Amount, userId),

                    WalletCreationDate = DateTime.UtcNow
                };
                await _weGOPAYDbContext.Wallet.AddAsync(nWallet);

                await _weGOPAYDbContext.SaveChangesAsync();

                return(nWallet.Id);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 2
0
        public async Task <IActionResult> CreateWallet([FromBody] CreateWalletDto createWallet, long idUser)
        {
            try
            {
                var nWallet = await _WalletService.CreateWallet(createWallet, idUser);

                return(Ok(nWallet));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
Esempio n. 3
0
        public async Task <IActionResult> CreateWallet(CreateWalletDto walletDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ResponseMessage.Message("Invalid Model", ModelState, walletDto)));
            }

            var loggedInUserId = _walletRepository.GetUserId();

            var userWallets = _walletRepository.GetWalletsByUserId(loggedInUserId);

            var user      = _userRepository.GetUserById(loggedInUserId);
            var userRoles = await _userRepository.GetUserRoles(user);

            if (userRoles.Contains("Noob") && userWallets.Count > 0)
            {
                return(BadRequest(ResponseMessage.Message("Already has a wallet",
                                                          "your account type is only allowed to have one wallet", walletDto)));
            }

            var wallet = new Wallet()
            {
                Balance    = 0,
                OwnerId    = loggedInUserId,
                CurrencyId = walletDto.CurrencyId,
                IsMain     = false
            };

            var created = _walletRepository.AddWallet(wallet);

            if (!created)
            {
                return(BadRequest(ResponseMessage.Message("Unable to create wallet",
                                                          "error encountered while creating wallet", walletDto)));
            }

            return(Ok(ResponseMessage.Message("Wallet successfully created", null, walletDto)));
        }