Пример #1
0
 public async Task AddOrUpdateSpecialBuget(CategoryData category, string monthId, double newBudget)
 {
     if (!_currentContext.Budgets.Any(n => n.CategoryId == category.Id && n.MonthId == monthId))
     {
         await _currentContext.Budgets.AddAsync(new BudgetData
         {
             CategoryId    = category.Id,
             BudgetAmmount = newBudget,
             MonthId       = monthId
         });
     }
     else
     {
         var budgetToUpdate = _currentContext.Budgets.Single(n => n.CategoryId == category.Id && n.MonthId == monthId);
         budgetToUpdate.BudgetAmmount = newBudget;
         _currentContext.Budgets.Update(budgetToUpdate);
     }
 }
Пример #2
0
        public async Task <int> AddCategory(CategoryData category)
        {
            {
                if (category.Id == 0)
                {
                    await _currentContext.ExpenseCategories.AddAsync(category);
                }

                else
                {
                    _currentContext.ExpenseCategories.Update(category);
                }


                await _currentContext.SaveChangesAsync();


                return(category.Id);
            }
        }
Пример #3
0
        public Task DeleteCategory(CategoryData category)
        {
            _currentContext.ExpenseCategories.Remove(category);

            return(Task.CompletedTask);
        }