public void AddPayment(DepositPaymentModel paymentModel)
 {
     var deposit = depositRepository.GetDepositById(paymentModel.DepositId);
     if (paymentModel.Type == DepositPaymentType.Income)
     {
         deposit.Balance += paymentModel.Amount;
     }
     else if (paymentModel.Type == DepositPaymentType.Outcome)
     {
         deposit.Balance -= paymentModel.Amount;
     }
     if (deposit.Balance < 1)
     {
         deposit.Balance = 0;
     }
     depositRepository.UpdateDeposit(deposit);
     var date = dateService.GetCurrentDate();
     var payment = new DepositPayment
     {
         Amount = paymentModel.Amount,
         DepositId = paymentModel.DepositId,
         Type = (int) paymentModel.Type,
         Date = date
     };
     depositPaymentRepository.CreatePayment(payment);
 }
Пример #2
0
 public ActionResult OutcomePayment(int depositId, DepositPaymentModel paymentModel)
 {
     var deposit = depositService.GetDepositById(depositId);
     if (deposit == null)
     {
         return new HttpNotFoundResult();
     }
     if (ModelState.IsValidField("Amount") && paymentModel.Amount > 0 && paymentModel.Amount <= 1000000000 &&
         paymentModel.Amount <= deposit.Balance)
     {
         paymentModel.Type = DepositPaymentType.Outcome;
         depositPaymentService.AddPayment(paymentModel);
         return RedirectToAction("EmployeeDetails", new {depositId = depositId});
     }
     paymentModel.DepositModel = deposit;
     ModelState.Clear();
     ModelState.AddModelError("", "Некорректное значение суммы");
     return View(paymentModel);
 }
Пример #3
0
 public ActionResult OutcomePayment(int depositId)
 {
     var deposit = depositService.GetDepositById(depositId);
     if (deposit == null)
     {
         return new HttpNotFoundResult();
     }
     var paymentModel = new DepositPaymentModel
     {
         DepositModel = deposit,
         DepositId = depositId
     };
     return View(paymentModel);
 }