Пример #1
0
 private static void UpdateOwner(AccountOwner updatingOwner, DtoAccountOwner owner)
 {
     updatingOwner.Email     = owner.Email;
     updatingOwner.FirstName = owner.FirstName;
     updatingOwner.LastName  = owner.LastName;
     updatingOwner.Password  = owner.Password;
 }
Пример #2
0
        /// <summary>
        /// Opens a new account for <paramref name="owner"/> with <paramref name="startBalance"/>.
        /// </summary>
        /// <param name="owner">person's full name</param>
        /// <param name="startBalance">first deposit amount</param>
        /// <returns>IBAN of a new account</returns>
        /// <exception cref="ArgumentException">Start balance is lesser than minimal.</exception>
        public string OpenAccount(AccountOwner owner, decimal startBalance)
        {
            if (owner == null)
            {
                throw new ArgumentNullException(nameof(owner));
            }

            BankAccount account;

            if (startBalance < 1000)
            {
                account = new StandardAccount(ibanGenerator.GenerateIBAN(), owner, startBalance, bonusPoints: 0);
            }
            else if (startBalance < 10000)
            {
                account = new GoldAccount(ibanGenerator.GenerateIBAN(), owner, startBalance, bonusPoints: 5);
            }
            else
            {
                account = new PlatinumAccount(ibanGenerator.GenerateIBAN(), owner, startBalance, bonusPoints: 10);
            }

            accountsRepo.Accounts.Create(account.ToDTO());
            accountsRepo.Save();

            return(account.IBAN);
        }
        /// <summary>
        /// Creates new bank account with specified type and adds it to the repository
        /// </summary>
        /// <param name="accountOwner">Account owner</param>
        /// <param name="accountID">Account ID</param>
        /// <param name="invoiceAmount">Invoice amount</param>
        /// <param name="bonusScores">Bonus Scores</param>
        /// <param name="accountType">Account type</param>
        private void Create(AccountOwner accountOwner, string accountID, decimal invoiceAmount, double bonusScores, AccountType accountType)
        {
            BankAccount newAccount;

            switch (accountType)
            {
            case AccountType.Base:
            {
                newAccount = new BaseAccount(accountOwner, accountID, invoiceAmount, bonusScores);
                repository.AddAccount(Mappers.BankAccountsMapper.ToDalBankAccount(newAccount, AccountType.Base));
            }
            break;

            case AccountType.Platinum:
            {
                newAccount = new PlatinumAccount(accountOwner, accountID, invoiceAmount, bonusScores);
                repository.AddAccount(Mappers.BankAccountsMapper.ToDalBankAccount(newAccount, AccountType.Platinum));
            }
            break;

            case AccountType.Gold:
            {
                newAccount = new GoldAccount(accountOwner, accountID, invoiceAmount, bonusScores);
                repository.AddAccount(Mappers.BankAccountsMapper.ToDalBankAccount(newAccount, AccountType.Gold));
            }
            break;

            default:
            {
                newAccount = new BaseAccount(accountOwner, accountID, invoiceAmount, bonusScores);
                repository.AddAccount(Mappers.BankAccountsMapper.ToDalBankAccount(newAccount, AccountType.Base));
            }
            break;
            }
        }
Пример #4
0
        public static AccountOwner ToBllAccountOwner(this DtoAccountOwner owner)
        {
            var result = new AccountOwner(owner.FirstName, owner.LastName, owner.Email);

            result.Accounts.AddRange(owner.Accounts.Select(account => account.ToBllAccount(result)));
            return(result);
        }
Пример #5
0
        public ActionResult UpdateOwnerDetails(AccountOwner OwnerDetails)
        {
            try
            {
                AccountOwner accountOwner = new AccountOwner();
                accountOwner                 = db.AccountOwner.Find(OwnerDetails.OwnerID);
                accountOwner.OwnerName       = OwnerDetails.OwnerName;
                accountOwner.UpdateBy        = AppUtils.GetLoginUserID();
                accountOwner.UpdateDate      = AppUtils.GetDateTimeNow();
                db.Entry(accountOwner).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();

                var owner =
                    new AccountOwnerViewModel()
                {
                    OwnerID   = accountOwner.OwnerID,
                    OwnerName = accountOwner.OwnerName,
                };
                var JSON = Json(new { success = true, owner = owner }, JsonRequestBehavior.AllowGet);
                JSON.MaxJsonLength = int.MaxValue;
                return(JSON);
            }
            catch (Exception ex)
            {
                return(Json(new { success = false }, JsonRequestBehavior.AllowGet));
            }
        }
Пример #6
0
 public static AccountOwnerDto ToAccountOwnerDto(this AccountOwner accountOwner) =>
 new AccountOwnerDto()
 {
     Email     = accountOwner.Email,
     FirstName = accountOwner.FirstName,
     LastName  = accountOwner.LastName
 };
Пример #7
0
        /// <summary>
        /// Creates new account of the given type and adds it to the storage
        /// </summary>
        /// <param name="accType"></param>
        /// <param name="owner"></param>
        /// <returns>account's id</returns>
        public string CreateNewAccount(AccountTypes accType, AccountOwner owner, IidGenerator generator, IPointsCounter counter)
        {
            if (owner == null)
            {
                throw new ArgumentNullException();
            }

            Account newAcc;

            switch (accType)
            {
            case AccountTypes.Basic:
                currStorage.Add(newAcc = new BaseAccount(owner, generator, counter));
                break;

            case AccountTypes.Golden:
                currStorage.Add(newAcc = new GoldenAccount(owner, generator, counter));
                break;

            case AccountTypes.Platinum:
                currStorage.Add(newAcc = new PlatinumAccount(owner, generator, counter));
                break;

            default:
                throw new Exception("Can't create an account");
            }

            return(newAcc.Accid);
        }
Пример #8
0
        public static AccountOwner ToAccountOwner(DalAccountOwner dalAccountOwner)
        {
            AccountOwner accountOwner = new AccountOwner(dalAccountOwner.FirstName, dalAccountOwner.LastName);

            accountOwner.AccountOwnerId = dalAccountOwner.AccountOwnerID;

            return(accountOwner);
        }
Пример #9
0
 public static DtoAccountOwner ToDtoAccountOwner(this AccountOwner owner, string password) =>
 new DtoAccountOwner
 {
     FirstName = owner.FirstName,
     LastName  = owner.LastName,
     Email     = owner.Email,
     Password  = password
 };
        private BankAccount InitializeFields(BankAccount account, AccountOwner owner, decimal balance, decimal bonusPoints)
        {
            account.Owner       = owner;
            account.Balance     = balance;
            account.BonusPoints = bonusPoints;

            return(account);
        }
Пример #11
0
 static bool ConfirmRegisterFormIsFilledOutCorrectly(AccountOwner owner, string Password, string PasswordConfirm)
 {
     if (Password != PasswordConfirm || owner.Email == null || owner.LastName == null || owner.FirstName == null || owner.PhoneNumber == null || Password == "")
     {
         return(false);
     }
     return(true);
 }
        public void StorageService_IncorrectWithdrawForAccType_ThrowsException()
        {
            AccountOwner   owner   = new AccountOwner("Ilya", "Priv");
            IidGenerator   gen     = new IdGeneratorBIC();
            IPointsCounter counter = new PointsCounter();
            string         id      = service.CreateNewAccount(AccountTypes.Basic, owner, gen, counter);

            Assert.Throws <ArgumentException>(() => service.Withdraw(id, 1000));
        }
        /// <summary>
        /// Opens new account with specified type
        /// </summary>
        /// <param name="accountOwner">Account owner</param>
        /// <param name="accountID">Account ID</param>
        /// <param name="invoiceAmount">Invoice amount</param>
        /// <param name="bonusScores">Bonus Scores</param>
        /// <param name="accountType">Account type</param>
        public void OpenAccount(AccountOwner accountOwner, string accountID, decimal invoiceAmount, double bonusScores, AccountType accountType)
        {
            if (accountOwner == null)
            {
                throw new ArgumentNullException("Account owner is not initialized.");
            }

            Create(accountOwner, accountID, invoiceAmount, bonusScores, accountType);
        }
Пример #14
0
 public static AccountOwnerDto ToDto(this AccountOwner accountOwner)
 {
     return(new AccountOwnerDto
     {
         Id = accountOwner.Id,
         FirstName = accountOwner.FirstName,
         LastName = accountOwner.LastName
     });
 }
Пример #15
0
 private static Account GetAccount(DalAccount account, AccountOwner accountOwner) =>
 new Account
 {
     AccountType  = GetAccountType(account),
     Amount       = account.Amount,
     Points       = account.Points,
     AccountId    = account.Id,
     AccountOwner = accountOwner
 };
Пример #16
0
        public static DalAccountOwner ToDalAccountOwner(AccountOwner owner)
        {
            DalAccountOwner dalAccountOwner = new DalAccountOwner();

            dalAccountOwner.FirstName = owner.FirstName;
            dalAccountOwner.LastName  = owner.LastName;

            return(dalAccountOwner);
        }
        public void NumberOfActiveAccountsTest()
        {
            //Arrange
            AccountOwner sampleAccountOwner = new AccountOwner();
            var          mockClass          = new Mock <BankAccount>(sampleAccountOwner);
            var          mockObject         = mockClass.Object;

            //Assert
            Assert.AreEqual(1, BankAccount.NumberOfAccounts);
        }
        public void StatusActiveTest()
        {
            //Arrange
            AccountOwner sampleAccountOwner = new AccountOwner();
            var          mockClass          = new Mock <BankAccount>(sampleAccountOwner);
            var          mockObject         = mockClass.Object;

            //Assert
            Assert.AreEqual(BankAccountStatus.Active, mockObject.Status);
        }
        public void Update(OwnerDTO owner)
        {
            //TODO if null
            AccountOwner ownerForUpdate = dbContext.Set <AccountOwner>().Find(owner.Id);

            ownerForUpdate.FirstName      = owner.FirstName;
            ownerForUpdate.LastName       = owner.LastName;
            ownerForUpdate.PassportNumber = owner.PassportNumber;
            ownerForUpdate.Email          = owner.Email;
        }
Пример #20
0
        public ActionResult Register(AccountOwner owner, string Password, string PasswordConfirm)
        {
            if (!ConfirmRegisterFormIsFilledOutCorrectly(owner, Password, PasswordConfirm))
            {
                TempData["errorMessage"] = (AccountOwner)owner;
                return(Redirect("/home/register"));
            }

            return(View());
        }
 public static OwnerDTO ToOwnerDTO(this AccountOwner ownerOrm)
 {
     return(new OwnerDTO()
     {
         Id = ownerOrm.Id,
         FirstName = ownerOrm.FirstName,
         LastName = ownerOrm.LastName,
         PassportNumber = ownerOrm.PassportNumber,
         Email = ownerOrm.Email
     });
 }
        public void StorageService_DeletingAccountTryingToGetDeletedInfo_ThrowsException()
        {
            AccountOwner   owner   = new AccountOwner("Ilya", "Priv");
            IidGenerator   gen     = new IdGeneratorBIC();
            IPointsCounter counter = new PointsCounter();
            string         id      = service.CreateNewAccount(AccountTypes.Basic, owner, gen, counter);

            service.DeleteAccount(id);

            Assert.Throws <NullReferenceException>(() => service.AccInfo(id));
        }
        public bool StorageService_WithdrawPointsCountInfoOutput_ExpectedResult(string info)
        {
            AccountOwner   owner   = new AccountOwner("Kirill", "Fidz");
            IidGenerator   gen     = new IdGeneratorBIC();
            IPointsCounter counter = new PointsCounter();
            string         id      = service.CreateNewAccount(AccountTypes.Basic, owner, gen, counter);

            service.Deposit(id, 1000);
            string result = info.Replace("tochange", id);

            return(result == service.AccInfo(id));
        }
Пример #24
0
        public IEnumerable <BankAccount> GetPersonalAccounts(AccountOwner owner)
        {
            var accounts = this.accountsRepo.Accounts.GetByOwner(owner.ToDTO());

            if (accounts != null)
            {
                foreach (var account in accounts)
                {
                    yield return(account.FromDTO());
                }
            }
        }
 public static Account ToOrmAccount(this DtoAccount account, AccountOwner accountOwner) =>
 new Account
 {
     AccountType = new AccountType
     {
         Name = account.AccountType
     },
     Balance       = account.Balance,
     Bonus         = account.Bonus,
     AccountNumber = account.AccountNumber,
     AccountOwner  = accountOwner
 };
        public static DtoAccountOwner ToDtoAccountOwner(this AccountOwner accountOwner)
        {
            var dtoOwner = new DtoAccountOwner
            {
                Email     = accountOwner.Email,
                FirstName = accountOwner.FirstName,
                LastName  = accountOwner.LastName,
                Password  = accountOwner.Password
            };

            dtoOwner.Accounts.AddRange(accountOwner.Accounts.Select(account => account.ToDtoAccount(dtoOwner)));
            return(dtoOwner);
        }
Пример #27
0
        public async Task <AccountOwner> AddAccountOwner(string OwnerID, string OwnerName, int AccountID)
        {
            User _owner = await _dbServices.GetUser(OwnerID);

            if (_owner == null)
            {
                _owner = await _dbServices.CreateUser(OwnerID, OwnerName);
            }

            AccountOwner _accountOwner = await _dbServices.AddAccountOwner(OwnerID, AccountID);

            return(_accountOwner);
        }
Пример #28
0
        /// <summary>
        /// Maps <paramref cref="DtoAccount"/> to <paramref cref="BankAccount"/>.
        /// </summary>
        public static BankAccount ToBllAccount(this DtoAccount account, AccountOwner owner)
        {
            var type       = GetBllAccountType(account.AccountType);
            var bllAccount = (BankAccount)Activator.CreateInstance(
                type,
                CryptoService.RijndaelDecrypt(account.AccountNumber, owner.Email),
                owner,
                account.Balance,
                account.Bonus);

            bllAccount.AccountType = type.Name;
            return(bllAccount);
        }
        public void DepositTest()
        {
            //Arrange
            AccountOwner sampleAccountOwner = new AccountOwner();
            var          mockClass          = new Mock <BankAccount> (sampleAccountOwner);
            var          mockObject         = mockClass.Object;

            //Act
            mockObject.Deposit(34.5m);

            //Assert
            Assert.AreEqual(34.5m, mockObject.Balance);
        }
Пример #30
0
        /// <summary>
        /// A method used to add a new account to the Customer's Account List
        /// </summary>
        private void AddThisAccount()
        {
            if (!AccountOwner.IsLoggedIn)
            {
                Console.WriteLine("You need to log in first before making this operation");
                return;
                //throw new InvalidOperationException("You need to log in first before making this operation");
            }

            //Adding this account the customer's account list
            AccountOwner.AddAccount(this);
            //Adding this account to the bank's Account list
            Bank.Accounts.Add(this);
        }