/// <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); }
private void OnOperationReport(object sender, OperationReportInfo info) { OperationReport(sender, info); }