コード例 #1
0
        /// <summary>
        /// Adds a new account to the repository.
        /// </summary>
        /// <param name="account">New account.</param>
        /// <exception cref="StorageException">
        /// It is thrown in the event of a storage error.
        /// </exception>
        public void AddAccount(AccountDal account)
        {
            if (ReferenceEquals(account, null))
            {
                throw new ArgumentNullException(nameof(account));
            }

            using (var context = new BankAccountContext())
            {
                context.Accounts.Add(account.ToAccountEF());
                context.SaveChanges();
            }
        }
コード例 #2
0
        public void UpdateBankAccount(BankAccount account)
        {
            using (var context = new BankAccountContext())
            {
                var bankAccount = context.BankAccounts.FirstOrDefault(m => m.AccountNumber == account.AccountNumber);

                if (bankAccount == null)
                {
                    throw new BankAccountNotFoundException("Account is not found.", nameof(account));
                }

                bankAccount.Balance     = account.Balance;
                bankAccount.BonusPoints = account.BonusPoints;
                bankAccount.Status      = account.Status;

                context.SaveChanges();
            }
        }
コード例 #3
0
        /// <summary>
        /// A method that removes a account <paramref name="account"/> from the repository.
        /// </summary>
        /// <param name="account">
        /// The Account for removal.
        /// </param>
        /// <exception cref="StorageException">
        /// It is thrown out in case of storage problems.
        /// </exception>
        public void RemoveAccount(AccountDal account)
        {
            if (ReferenceEquals(account, null))
            {
                throw new ArgumentNullException(nameof(account));
            }

            using (var context = new BankAccountContext())
            {
                var accountForRemove = FindAccount(account, context);

                if (ReferenceEquals(accountForRemove, null))
                {
                    throw new AccountNotFoundException();
                }

                context.Accounts.Remove(accountForRemove);

                context.SaveChanges();
            }
        }
コード例 #4
0
        /// <summary>
        /// Updates the account information in the repository.
        /// </summary>
        /// <param name="account">Account to update.</param>
        /// <exception cref="StorageException">
        /// It is thrown out in case of storage problems.
        /// </exception>
        public void UpdateAccount(AccountDal account)
        {
            if (ReferenceEquals(account, null))
            {
                throw new ArgumentNullException(nameof(account));
            }

            using (var context = new BankAccountContext())
            {
                var accountForUpdate = FindAccount(account, context);

                if (ReferenceEquals(accountForUpdate, null))
                {
                    throw new AccountNotFoundException();
                }

                accountForUpdate.Balance = account.Balance;
                accountForUpdate.Bonus   = account.Bonus;

                context.SaveChanges();
            }
        }
コード例 #5
0
        public void AddBankAccount(BankAccount account)
        {
            using (var context = new BankAccountContext())
            {
                var bankAccount = context.BankAccounts.FirstOrDefault(m => m.AccountNumber == account.AccountNumber);

                if (bankAccount == null)
                {
                    context.BankAccounts.Add(account);

                    var accountOwner = context.Owners.FirstOrDefault(m => m.AccountOwnerId == account.Owner.AccountOwnerId);
                    if (accountOwner == null)
                    {
                        context.Owners.Add(account.Owner);
                    }

                    context.SaveChanges();
                    return;
                }
            }

            throw new ArgumentException("This value is already exists.", nameof(account));
        }
コード例 #6
0
 public void Save()
 {
     using (var context = new BankAccountContext())
         context.SaveChanges();
 }