Exemplo n.º 1
0
 public static Account ToInterfaceAccount(this DalAccount dalAccount, BankUser bankUser) =>
 new Account
 {
     Id          = CryptographyHelper.Decrypt(dalAccount.Id, dalAccount.BankUser.Email),
     BankUser    = bankUser,
     Sum         = dalAccount.Sum,
     Type        = GetAccountType(dalAccount.Type),
     BonusPoints = dalAccount.BonusPoints
 };
 private void UpdateAccount(AccountContext db, Account dbAccount, DalAccount account, Owner accountOwner, AccountType accountType)
 {
     dbAccount.AccountType    = accountType;
     dbAccount.AccountOwnerId = accountOwner.Id;
     dbAccount.CurrentSum     = account.Balance;
     dbAccount.BonusPoints    = account.BenefitPoints;
     dbAccount.AccountNumber  = account.AccountNumber;
     db.SaveChanges();
 }
Exemplo n.º 3
0
        /// <summary>
        /// Adds entity of the <see cref="DalAccount"/> class to context
        /// </summary>
        /// <param name="entity"> Entity for saving </param>
        /// <exception cref="ArgumentNullException">
        ///     <paramref name="entity"/> is null.
        /// </exception>
        public void Create(DalAccount entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException(nameof(entity));
            }

            context.Set <Account>().Add(entity.ToAccount());
        }
 /// <summary>
 /// Add account to file
 /// </summary>
 /// <param name="account"></param>
 public void AddAccount(DalAccount account)
 {
     if (account is null)
     {
         throw new ArgumentNullException(nameof(account));
     }
     AppendAccountToFile(account);
     _accounts.Add(account);
 }
Exemplo n.º 5
0
 public static Account Map(DalAccount acc)
 {
     return(new Account()
     {
         Id = acc.Id,
         Balance = acc.Balance,
         BonusPoints = acc.BonusPoints
     });
 }
 private static void Writer(BinaryWriter binaryWriter, DalAccount accounts)
 {
     binaryWriter.Write(accounts.Id);
     binaryWriter.Write(accounts.FirstName);
     binaryWriter.Write(accounts.LastName);
     binaryWriter.Write(accounts.AccountBalance);
     binaryWriter.Write(accounts.AccountBonus);
     binaryWriter.Write(accounts.AccountType);
 }
        public void TestAllAtOnce(string firstName, string secondName, string accountId)
        {
            // Arrange.
            var repositoryMock  = new Mock <IAccountRepository>();
            var mailServiceMock = new Mock <IMailService>();
            var unitOfWorkMock  = new Mock <IUnitOfWork>();

            var accountIdServiceMock = new Mock <IAccountIdService>(MockBehavior.Strict);

            accountIdServiceMock.Setup(service => service.GenerateAccountId(firstName, secondName))
            .Returns(accountId);

            var accountService = new AccountService(unitOfWorkMock.Object, repositoryMock.Object, mailServiceMock.Object);

            // Act.
            accountService.OpenAccount(firstName, secondName, 100m, "*****@*****.**", accountIdServiceMock.Object);

            var dalAccount = new DalAccount
            {
                AccountType     = "Base",
                BonusPoints     = 0,
                CurrentSum      = 100m,
                Id              = accountId,
                OwnerFirstName  = firstName,
                OwnerSecondName = secondName,
                OwnerEmail      = "*****@*****.**"
            };

            repositoryMock.Setup(repository => repository.GetAccounts())
            .Returns(new[] { dalAccount });

            accountService.DepositMoney(accountId, 100m);
            accountService.DepositMoney(accountId, 100m);
            accountService.WithdrawMoney(accountId, 100m);

            accountService.CloseAccount(accountId);

            // Assert.
            Predicate <DalAccount> predicate = account =>
                                               string.Equals(account.Id, accountId, StringComparison.Ordinal);

            accountIdServiceMock.Verify(
                service => service.GenerateAccountId(firstName, secondName), Times.AtLeastOnce);

            repositoryMock.Verify(
                repository => repository.GetAccounts(), Times.AtLeastOnce);

            repositoryMock.Verify(
                repository => repository.AddAccount(It.Is <DalAccount>(account => predicate(account))), Times.Once);

            repositoryMock.Verify(
                repository => repository.UpdateAccount(It.Is <DalAccount>(account => predicate(account))), Times.Exactly(3));

            repositoryMock.Verify(
                repository => repository.RemoveAccount(It.Is <DalAccount>(account => predicate(account))), Times.Once);
        }
 public static AccountEntity ToAccount(this DalAccount accountEntity)
 {
     return(new AccountEntity()
     {
         AccountHolder = accountEntity.AccountHolder.ToHolder(),
         Balance = accountEntity.Balance,
         AccountNumber = accountEntity.AccountNumber,
         BonusPoints = accountEntity.BonusPoints,
     });
 }
        public void RemoveAccount(DalAccount account)
        {
            if (account == null)
            {
                throw new ArgumentNullException(nameof(account));
            }

            _accounts.Remove(_accounts.Find(acc => acc.Id == account.Id));
            AppendAccountsToFile(_accounts);
        }
        public void CreateAccount(DalAccount account)
        {
            if (account == null)
            {
                throw new ArgumentNullException(nameof(account));
            }

            _accounts.Add(account);
            AppendAccountToFile(account);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Remove account from file
        /// </summary>
        /// <param name="account">account that is removing</param>
        public void RemoveAccount(DalAccount account)
        {
            if (ReferenceEquals(account, null))
            {
                throw new ArgumentNullException(nameof(account));
            }

            _accounts.Remove(account);
            AppendAccountsToFile(_accounts);
        }
Exemplo n.º 12
0
 public static Account ConvertToAccount(this DalAccount dalAccount)
 {
     return((Account)Activator.CreateInstance(
                typeof(AccountType),
                dalAccount.Id,
                dalAccount.OwnerFirstName,
                dalAccount.OwnerLastName,
                dalAccount.Amount,
                dalAccount.Points));
 }
 /// <summary>
 /// Update account, overwrite file
 /// </summary>
 /// <param name="account"></param>
 public void UpdateAccount(DalAccount account)
 {
     if (account is null)
     {
         throw new ArgumentNullException(nameof(account));
     }
     _accounts.Remove(account);
     _accounts.Add(account);
     AppendAccountsToFile(_accounts);
 }
Exemplo n.º 14
0
 public static Account ConvertToAccount(this DalAccount dalAccount)
 {
     return((Account)Activator.CreateInstance(
                GetAccountType(dalAccount.AccountType),
                dalAccount.Id,
                dalAccount.FirstName,
                dalAccount.LastName,
                dalAccount.AccountBalance,
                dalAccount.AccountBonus));
 }
Exemplo n.º 15
0
        public void Create(DalAccount e)
        {
            var account = new Account()
            {
                Number  = Convert.ToInt32(e.AccountNumber),
                OwnerId = e.Id
            };

            context.Set <Account>().Add(account);
        }
Exemplo n.º 16
0
 public static Account ConvertToAccount(this DalAccount dalAccount)
 {
     return((Account)Activator.CreateInstance(
                GetAccountType(dalAccount.AccountType),
                dalAccount.Id,
                dalAccount.FirstName,
                dalAccount.LastName,
                dalAccount.Amount,
                dalAccount.Points,
                dalAccount.Email));
 }
Exemplo n.º 17
0
        /// <summary>
        /// Removes entity of the <see cref="DalAccount"/> class from context
        /// </summary>
        /// <param name="entity"> Entity for removing </param>
        /// <exception cref="ArgumentNullException">
        ///     <paramref name="entity"/> is null.
        /// </exception>
        public void Delete(DalAccount entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException(nameof(entity));
            }

            var account = context.Set <Account>().Single(a => a.Id == entity.Id);

            account.IsOpen = false;
        }
Exemplo n.º 18
0
        internal static Account ToBLLAccount(this DalAccount dalAccount)
        {
            Account account = ResolveDalAccountType(dalAccount);

            account.Id            = dalAccount.Id;
            account.AccountNumber = dalAccount.AccountNumber;
            account.AccountHolder = dalAccount.AccountHolder.ToBllAccountHolder();
            account.Balance       = dalAccount.Balance;
            account.Bonus         = dalAccount.Bonus;
            return(account);
        }
 private static void WriteAccountToFile(
     BinaryWriter binaryWriter, DalAccount account)
 {
     binaryWriter.Write(account.AccountType);
     binaryWriter.Write(account.Id);
     binaryWriter.Write(account.OwnerFirstName);
     binaryWriter.Write(account.OwnerSecondName);
     binaryWriter.Write(account.CurrentSum);
     binaryWriter.Write(account.BonusPoints);
     binaryWriter.Write(account.OwnerEmail);
 }
Exemplo n.º 20
0
        public void Delete(DalAccount dalAccount)
        {
            DalAccount deleteAccount = GetById(dalAccount.Id);

            if (deleteAccount == null)
            {
                return;
            }

            Accounts.Remove(deleteAccount);
        }
        public void UpdateAccount(DalAccount account)
        {
            if (account == null)
            {
                throw new ArgumentNullException(nameof(account));
            }
            DalAccount updetedAcc = GetAccount(account.AccountNumber);

            repository.Remove(updetedAcc);
            repository.Add(account);
        }
Exemplo n.º 22
0
        internal static DalAccount ToDalAccount(this Account account)
        {
            DalAccount dalAccount = new DalAccount();

            dalAccount.Id            = account.Id;
            dalAccount.Type          = account.Type;
            dalAccount.AccountNumber = account.AccountNumber;
            dalAccount.AccountHolder = account.AccountHolder.ToDalAccountHolder();
            dalAccount.Balance       = account.Balance;
            dalAccount.Bonus         = account.Bonus;
            return(dalAccount);
        }
Exemplo n.º 23
0
        public void Delete(DalAccount e)
        {
            var account = new Account()
            {
                Id     = e.Id,
                Owner  = e.OwnerName.ToString(),
                RoleId = e.RoleId
            };

            account = context.Set <User>().Single(u => u.Id == account.Id);
            context.Set <User>().Remove(account);
        }
Exemplo n.º 24
0
 internal static Account ResolveDalAccountType(DalAccount account)
 {
     if (account.Type == "base")
     {
         return(new BaseAccount());
     }
     if (account.Type == "gold")
     {
         return(new GoldAccount());
     }
     return(null);
 }
Exemplo n.º 25
0
        public void Create(DalAccount dalAccount)
        {
            if (ReferenceEquals(dalAccount, null))
            {
                throw new ArgumentException(nameof(dalAccount));
            }

            var account = dalAccount.ToOrmAccount();

            SetTypeAndOwner(account);
            context.Set <Account>().Add(account);
        }
        public static Account FromDalAccount(DalAccount account)
        {
            Account newAccount = (Account)Activator.CreateInstance(GetBllAccountType(account.AccountType), account.AccountNumber);

            newAccount.Id            = account.Id;
            newAccount.Balance       = account.Balance;
            newAccount.BenefitPoints = account.BenefitPoints;
            newAccount.OwnerEmail    = account.OwnerEmail;
            newAccount.Open          = account.Open;

            return(newAccount);
        }
Exemplo n.º 27
0
 /// <summary>
 /// Convert data access layer account to object relational account.
 /// </summary>
 /// <param name="dalAccount">data access layer account</param>
 /// <returns>Object relation account.</returns>
 public static OrmAccount ToOrmAccount(this DalAccount dalAccount)
 {
     return(new OrmAccount()
     {
         Id = dalAccount.Id,
         Name = dalAccount.Name,
         Surname = dalAccount.Surname,
         Amount = dalAccount.Amount,
         Points = dalAccount.Points,
         Type = dalAccount.Type
     });
 }
Exemplo n.º 28
0
 public static Account ToOrmAccount(this DalAccount dalAccount, BankUser bankUser) =>
 new Account
 {
     AccountId   = dalAccount.Id,
     AccountType = new AccountType {
         Type = dalAccount.Type
     },
     Sum         = dalAccount.Sum,
     BonusPoints = dalAccount.BonusPoints,
     BankUser    = bankUser,
     BankUserId  = bankUser.Id
 };
        /// <summary>
        /// This method returns the telephone numbers for digital telephone service for a statement.
        /// </summary>
        /// <param name="accountNumber13"></param>
        /// <param name="phoneNumber"></param>
        /// <returns></returns>
        public string InquireStatementCode(
            [RequiredItem()][StringLength(13, 13)][CustomerAccountNumber()] string accountNumber13,
            [RequiredItem()][StringLength(4, 4)] string phoneNumber)
        {
            BillingLogEntry logEntry = new BillingLogEntry(eBillingActivityType.StatementCodeInquiry, accountNumber13, phoneNumber);

            using (Log log = CreateLog(logEntry))
            {
                try
                {
                    // validate the parameters.
                    MethodValidator validator = new MethodValidator(MethodBase.GetCurrentMethod(), accountNumber13, phoneNumber);
                    validator.Validate();

                    // convert the accountNumber.
                    CustomerAccountNumber accountNumber = (CustomerAccountNumber)TypeDescriptor.GetConverter(
                        typeof(CustomerAccountNumber)).ConvertFrom(accountNumber13);

                    // get the siteid/sitecode information
                    PopulateSiteInfo(accountNumber);
                    logEntry.SiteId = this.SiteId;

                    // use dal to get statement code
                    string     statementCode = null;
                    DalAccount dalAccount    = new DalAccount();
                    statementCode = dalAccount.GetStatementCode(SiteId, SiteCode, accountNumber.AccountNumber9, phoneNumber);

                    // if no statement code is found throw ex
                    if (statementCode == null || statementCode == string.Empty)
                    {
                        throw new InvalidAccountNumberException(
                                  string.Format(__noStatementCodeForAccountExceptionMessage, accountNumber.AccountNumber13, phoneNumber));
                    }
                    return(statementCode.PadLeft(3, '0'));
                }
                catch (ValidationException ve)
                {
                    logEntry.SetError(new ExceptionFormatter(ve).Format());
                    throw;
                }
                catch (BusinessLogicLayerException blle)
                {
                    logEntry.SetError(new ExceptionFormatter(blle).Format());
                    throw;
                }
                catch (Exception e)
                {
                    logEntry.SetError(new ExceptionFormatter(e).Format());
                    throw new UnexpectedSystemException(e);
                }
            }
        }
        private void AppendAccountToFile(DalAccount account)
        {
            if (string.IsNullOrEmpty(_path))
            {
                throw new ArgumentException(_path);
            }

            using (var binaryWriter = new BinaryWriter(File.Open(_path, FileMode.Append,
                                                                 FileAccess.Write, FileShare.None)))
            {
                Writer(binaryWriter, account);
            }
        }