public async Task <IActionResult> PutIncome(int id, IncomeModel income)
        {
            if (id != income.StatementId)
            {
                return(BadRequest());
            }

            _context.Entry(income).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!IncomeExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <IActionResult> PutCategory(int id, Category category)
        {
            if (id != category.CategoryId)
            {
                return(BadRequest());
            }

            _context.Entry(category).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CategoryExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <bool> Delete(T value)
        {
            bool isDeleted = false;

            if (_entities.Contains(value))
            {
                _entities.Remove(value);
                await _context.SaveChangesAsync();

                isDeleted = true;
            }

            return(isDeleted);
        }
Esempio n. 4
0
        public async Task <ActionResult <Budget> > PostBudget(Budget budget)
        {
            var catogeries = _context.Categories
                             .Include(c => c.Statements)
                             .ToList()
                             .Where(c => budget.Categories.FirstOrDefault(bc => c.Name == bc.Name) != null && c.Statements.Any(s => s is Expense))
                             .ToList();

            budget.Categories.Clear();

            budget.Categories = catogeries;

            _context.Budgets.Add(budget);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetBudget", new { id = budget.BudgetId }, budget));
        }