Esempio n. 1
0
        public async Task <IActionResult> Add(AddIncomeRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(Failure());
            }

            return(await _incomeService.Add(request));
        }
Esempio n. 2
0
        public async Task <IActionResult> Add(AddIncomeRequest request)
        {
            var userId = _jwtService.GetUserId();

            if (request.Amount < 0)
            {
                return(Failure());
            }
            var income = new Income()
            {
                CategoryId = request.CategoryId,
                UserId     = userId,
                Amount     = request.Amount,
                CurrencyId = request.CurrencyId
            };

            _context.Incomes.Add(income);
            await _context.SaveChangesAsync();

            var addedIncomes = _context.Incomes.Where(i => i.Id == income.Id)
                               .Include(i => i.Currency).Include(i => i.Category).FirstOrDefault();

            return(Success(ConvertToVM(addedIncomes)));
        }