/// <summary> /// Deposit to current account. /// </summary> /// <param name="accNumber"> /// Account number. /// </param> /// <param name="amount"> /// Amount of deposit. /// </param> /// <exception cref="ArgumentNullException"> /// Throws if current account number is null. /// </exception> /// <exception cref="ArgumentException"> /// Throws if deposit amount less than 0. /// </exception>> public void Deposit(string accNumber, decimal amount) { if (string.IsNullOrEmpty(accNumber)) { throw new ArgumentNullException(nameof(accNumber)); } if (amount < 0) { throw new ArgumentException($"Deposit amount ({nameof(amount)}) must be more than 0"); } AbstractAccount tempAcc = repository.GetAccount(accNumber); tempAcc.Balance += amount; tempAcc.BonusPoints += CalculateBonusPoints(tempAcc.Status, amount); repository.Save(tempAcc); OperationReportInfo info = new OperationReportInfo() { AccNumber = accNumber, TypeOperaton = "Deposit", Amount = amount }; OnOperationReport(this, info); }
/// <summary> /// Withdraw from current account. /// </summary> /// <param name="accNumber"> /// Account number. /// </param> /// <param name="amount"> /// Amount of withdraw. /// </param> /// <exception cref="ArgumentNullException"> /// Throws if current account number is null. /// </exception> /// <exception cref="ArgumentException"> /// Throws if withdraw amount less than 0. /// </exception>> public void Withdraw(string accNumber, decimal amount) { if (string.IsNullOrEmpty(accNumber)) { throw new ArgumentNullException(nameof(accNumber)); } if (amount < 0) { throw new ArgumentException($"Withdraw amount ({nameof(amount)}) must be more than 0"); } AbstractAccount tempAcc = repository.GetAccount(accNumber); if ((tempAcc.Balance - tempAcc.MinEdgeWithdraw) < amount) { throw new Exception("Not enough money"); } tempAcc.Balance -= amount; tempAcc.BonusPoints -= CalculateBonusPoints(tempAcc.Status, amount); repository.Save(tempAcc); OperationReportInfo info = new OperationReportInfo() { AccNumber = accNumber, TypeOperaton = "Withdraw", Amount = amount }; OnOperationReport(this, info); }
public void Save(AbstractAccount acc) { if (ReferenceEquals(acc, null)) { throw new ArgumentNullException(nameof(acc)); } if (dictionaryRepository.ContainsKey(acc.AccNumber)) { dictionaryRepository[acc.AccNumber] = acc; return; } dictionaryRepository.Add(acc.AccNumber, acc); }
/// <summary> /// Add new account to repository. /// </summary> /// <param name="name"> /// Holder name. /// </param> /// <param name="email"> /// Holder e-mail. /// </param> /// <param name="accountFactory"> /// Factory for current account status. /// </param> /// <exception cref="ArgumentNullException"> /// Throws if name or e-mail is null. /// </exception>. public override void NewAccount(string name, string email, AbstractAccountFactory accountFactory) { if (string.IsNullOrEmpty(name)) { throw new ArgumentNullException(nameof(name)); } if (string.IsNullOrEmpty(email)) { throw new ArgumentNullException(nameof(email)); } AbstractAccount newAccount = accountFactory.GetNewAccount(new NumGenerator()); newAccount.Name = name; newAccount.Email = email; repository.Save(newAccount); }