コード例 #1
0
ファイル: WalletServices.cs プロジェクト: SebigDev/weGOPAY
        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;
            }
        }
コード例 #2
0
        public async Task <long> CreateUser(CreateUserDto model)
        {
            //PASSWORD ENCRYPTION
            byte[] passwordHash, passwordSalt;
            CreatePasswordEncrypt(model.Password, out passwordHash, out passwordSalt);
            var nModel = new User
            {
                PasswordHash       = passwordHash,
                PasswordSalt       = passwordSalt,
                EmailAddress       = model.EmailAddress,
                Fullname           = model.Fullname,
                CountryOfOrigin    = model.CountryOfOrigin,
                CountryOfResidence = model.CountryOfResidence,
                Gender             = model.Gender.Description(),
                Status             = UserStatusEnum.Registered.Description(),
                UserId             = Guid.NewGuid().ToString(),
            };
            await _weGOPAYDbContext.User.AddAsync(nModel);

            await _weGOPAYDbContext.SaveChangesAsync();

            return(nModel.Id);
        }
コード例 #3
0
        public async Task <long> MakeTransactionRequest(RequestWalletTransactionDto model)
        {
            #region Initiating Currency Transaction Request
            try
            {
                WalletTransaction nMakeTransaction = new WalletTransaction();

                var checkTransaction = await _weGOPAYDbContext.Wallet.Where(x => x.UserId == model.UserId).FirstOrDefaultAsync();

                if ((int)model.RequestCurrency == (int)CurrencyEnum.Naira && model.RequestAmount <= checkTransaction.NairaBalance)
                {
                    nMakeTransaction = new WalletTransaction
                    {
                        UserId            = model.UserId,
                        Amount            = model.RequestAmount,
                        RequestCurrency   = (int)CurrencyEnum.Naira,
                        ResponseCurrency  = (int)model.ResponseCurrency,
                        TransactionStatus = (int)TransactionStatus.Requested,
                    };
                }
                if ((int)model.RequestCurrency == (int)CurrencyEnum.USDollar && model.RequestAmount <= checkTransaction.NairaBalance)
                {
                    nMakeTransaction = new WalletTransaction
                    {
                        UserId            = model.UserId,
                        Amount            = model.RequestAmount,
                        RequestCurrency   = (int)CurrencyEnum.USDollar,
                        ResponseCurrency  = (int)model.ResponseCurrency,
                        TransactionStatus = (int)TransactionStatus.Requested,
                    };
                }
                if ((int)model.RequestCurrency == (int)CurrencyEnum.BritishPound && model.RequestAmount <= checkTransaction.NairaBalance)
                {
                    nMakeTransaction = new WalletTransaction
                    {
                        UserId            = model.UserId,
                        Amount            = model.RequestAmount,
                        RequestCurrency   = (int)CurrencyEnum.BritishPound,
                        ResponseCurrency  = (int)model.ResponseCurrency,
                        TransactionStatus = (int)TransactionStatus.Requested,
                    };
                }
                if ((int)model.RequestCurrency == (int)CurrencyEnum.Euro && model.RequestAmount <= checkTransaction.NairaBalance)
                {
                    nMakeTransaction = new WalletTransaction
                    {
                        UserId            = model.UserId,
                        Amount            = model.RequestAmount,
                        RequestCurrency   = (int)CurrencyEnum.Euro,
                        ResponseCurrency  = (int)model.ResponseCurrency,
                        TransactionStatus = (int)TransactionStatus.Requested,
                    };
                }
                if ((int)model.RequestCurrency == (int)CurrencyEnum.Yen && model.RequestAmount <= checkTransaction.NairaBalance)
                {
                    nMakeTransaction = new WalletTransaction
                    {
                        UserId            = model.UserId,
                        Amount            = model.RequestAmount,
                        RequestCurrency   = (int)CurrencyEnum.Yen,
                        ResponseCurrency  = (int)model.ResponseCurrency,
                        TransactionStatus = (int)TransactionStatus.Requested,
                    };
                }
                await _weGOPAYDbContext.WalletTransaction.AddAsync(nMakeTransaction);

                await _weGOPAYDbContext.SaveChangesAsync();

                return(nMakeTransaction.Id);
            }
            catch (Exception ex)
            {
                throw ex;
            }

            #endregion
        }