public void AddPayment(CreditPaymentModel paymentModel)
 {
     var credit = creditRepository.GetCreditById(paymentModel.CreditId);
     var rest = paymentModel.MainAmount - credit.PercentageDebt;
     decimal mainMinus, percentMinus;
     if (rest >= 0)
     {
         mainMinus = rest;
         percentMinus = credit.PercentageDebt;
     }
     else
     {
         mainMinus = 0;
         percentMinus = paymentModel.MainAmount;
     }
     credit.MainDebt -= mainMinus;
     credit.PercentageDebt -= percentMinus;
     if (credit.MainDebt < 1)
     {
         credit.MainDebt = 0;
     }
     if (credit.PercentageDebt < 1)
     {
         credit.PercentageDebt = 0;
     }
     creditRepository.UpdateCredit(credit);
     var date = dateService.GetCurrentDate();
     var payment = new CreditPayment
     {
         MainAmount = mainMinus,
         PercentsAmount = percentMinus,
         CreditId = paymentModel.CreditId,
         Type = (int)paymentModel.Type,
         Date = date,
     };
     creditPaymentRepository.CreatePayment(payment);
 }
Пример #2
0
 public ActionResult IncomePayment(int creditId, CreditPaymentModel paymentModel)
 {
     var credit = creditService.GetCreditById(creditId);
     if (credit == null)
     {
         return new HttpNotFoundResult();
     }
     if (ModelState.IsValidField("MainAmount") && paymentModel.MainAmount > 0 &&
         paymentModel.MainAmount <= 1000000000 &&
         paymentModel.MainAmount <= credit.MainDebt + credit.PercentageDebt)
     {
         paymentModel.Type = CreditPaymentType.Payment;
         creditPaymentService.AddPayment(paymentModel);
         return RedirectToAction("EmployeeDetails", new {creditId = creditId});
     }
     paymentModel.CreditModel = credit;
     ModelState.Clear();
     ModelState.AddModelError("", "Некорректное значение суммы");
     return View(paymentModel);
 }
Пример #3
0
 public ActionResult IncomePayment(int creditId)
 {
     var credit = creditService.GetCreditById(creditId);
     if (credit == null)
     {
         return new HttpNotFoundResult();
     }
     var paymentModel = new CreditPaymentModel
     {
         CreditModel = credit,
         CreditId = creditId
     };
     return View(paymentModel);
 }