Example #1
0
        public async Task <double> TransferByID(double transferAmount, int userId, string phoneNumber)
        {
            var updatedBalance = 0.0;

            using (var dbContext = new DigitalWalletDbContext())
            {
                var accountrecord = await this.GetAccountInformation(userId);

                accountrecord.TotalBalance -= transferAmount;
                if (accountrecord.TotalBalance < 0)
                {
                    throw new Exception("Insufficient account balance! Please deposit and try again.");
                }

                dbContext.Account.Update(accountrecord);

                var registerRecord   = dbContext.Register.Where(l => l.PhoneNumber == (Convert.ToString(phoneNumber))).FirstOrDefault();
                var transferRecordId = registerRecord.RegisterId;
                var accountInfo      = dbContext.Account.Where(m => m.Accountid == transferRecordId).FirstOrDefault();
                accountInfo.TotalBalance += transferAmount;

                dbContext.Account.Update(accountInfo);
                await dbContext.SaveChangesAsync();

                updatedBalance = accountrecord.TotalBalance;
            }

            return(updatedBalance);
        }
Example #2
0
 public async Task InsertRecord(Register register)
 {
     using (var dbContext = new DigitalWalletDbContext())
     {
         dbContext.Register.Add(register);
         await dbContext.SaveChangesAsync();
     }
 }
Example #3
0
        public async Task <double> DepositByID(int userId, double depositAmount)
        {
            var updatedBalance = 0.0;

            using (var dbContext = new DigitalWalletDbContext())
            {
                var accountrecord = await this.GetAccountInformation(userId);

                accountrecord.TotalBalance += depositAmount;
                dbContext.Account.Update(accountrecord);
                await dbContext.SaveChangesAsync();

                updatedBalance = accountrecord.TotalBalance;
            }

            return(updatedBalance);
        }
        public async Task <bool> IsValidLogin(Login login, Models.Register user)
        {
            using (var dbContext = new DigitalWalletDbContext())
            {
                if (user != null)
                {
                    if (string.Equals(user.Password, login.Password))
                    {
                        var loginHistory = new LoginHistory();
                        loginHistory.Email       = user.Email;
                        loginHistory.PhoneNumber = user.PhoneNumber;
                        loginHistory.RegisterId  = user.RegisterId;
                        dbContext.LoginHistory.Add(loginHistory);
                        await dbContext.SaveChangesAsync();

                        return(true);
                    }
                }

                return(false);
            }
        }