Ejemplo n.º 1
0
        public async Task <ActionResult> ClosePartially(DebtEditModel model)
        {
            Debt debt = null;

            if (ModelState.IsValid)
            {
                try
                {
                    await _createCloseDebtService.PartialCloseAsync(model.DebtId, model.Sum, model.AccountId);
                }
                catch (ServiceException e)
                {
                    throw new WebUiException(
                              $"Ошибка в контроллере {nameof(DebtController)} в методе {nameof(ClosePartially)}", e);
                }
                catch (ArgumentOutOfRangeException)
                {
                    ModelState.AddModelError("", "Введенная сумма больше суммы долга");
                    debt = await _debtService.GetItemAsync(model.DebtId);
                    await FillDebtViewModel(debt, model);

                    return(PartialView("_ClosePartially", model));
                }

                return(RedirectToAction("DebtList"));
            }
            debt = await _debtService.GetItemAsync(model.DebtId);
            await FillDebtViewModel(debt, model);

            return(PartialView("_ClosePartially", model));
        }
        public async Task PartialCloseAsync(int debtId, decimal sum, int accountId)
        {
            var debt = await _debtRepository.GetItemAsync(debtId);

            if (debt.Summ < sum)
            {
                throw new ArgumentOutOfRangeException(nameof(sum), "Введенная сумма больше суммы долга");
            }
            await _createCloseDebtService.PartialCloseAsync(debtId, sum, accountId);

            await CreateClosedDebtPayingItem(debt, sum);
        }