Exemplo n.º 1
0
        public async Task <ActionResult> Add(WebUser user, DebtsAddModel model)
        {
            if (ModelState.IsValid)
            {
                var debt = new Debt()
                {
                    DateBegin    = DateTime.Now,
                    Person       = model.Person,
                    TypeOfFlowId = model.TypeOfFlowId,
                    AccountId    = model.AccountId,
                    Summ         = model.Summ,
                    UserId       = user.Id
                };
                try
                {
                    await _debtService.CreateAsync(debt);
                }
                catch (ServiceException e)
                {
                    throw new WebUiException($"Ошибка в контроллере {nameof(DebtController)} в методе {nameof(Add)}", e);
                }

                return(RedirectToAction("DebtList"));
            }
            model.Accounts = (await AccountList(user.Id)).ToList();
            return(PartialView(model));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Create([FromBody] CreateDebt dto)
        {
            if (dto == null)
            {
                return(BadRequest());
            }

            try
            {
                dto.UserId = IdentityHelper.GetUserId(User);
            }
            catch (UnauthorizedAccessException)
            {
                return(Unauthorized());
            }

            int id = await _debtService.CreateAsync(dto);

            return(StatusCode(201, id));
        }