Ejemplo n.º 1
0
 public Budget Read(Func <Budget, bool> predicate)
 {
     using (var dbcontext = new BudgetEntities())
     {
         var firstBudget = dbcontext.Budgets.FirstOrDefault(predicate);
         return(firstBudget);
     }
 }
Ejemplo n.º 2
0
        public void Save(Budget budget)
        {
            using (var dbcontext = new BudgetEntities())
            {
                var budgetFromDb = dbcontext.Budgets.FirstOrDefault(x => x.YearMonth == budget.YearMonth);

                if (budgetFromDb == null)
                {
                    dbcontext.Budgets.Add(budget);
                }
                else
                {
                    budgetFromDb.Amount = budget.Amount;
                }

                dbcontext.SaveChanges();
            }
        }