Пример #1
0
 public static List <Transaction> GetTransactionByGoalId(int goalId)
 {
     using (var db = new GoalDataContext())
     {
         return(db.Set <Transaction>().Where(x => x.GoalId == goalId).ToList());
     }
 }
Пример #2
0
 public async static Task DeleteItem <T>(T itemToDelete) where T : class
 {
     using (var db = new GoalDataContext())
     {
         db.Set <T>().Remove(itemToDelete);
         await db.SaveChangesAsync();
     }
 }
Пример #3
0
        public static T GetItem <T>(int id) where T : class
        {
            var item = default(T);

            using (var db = new GoalDataContext())
            {
                item = db.Set <T>().ToList().FirstOrDefault(x => ((ITableItem)x).GetId() == id);
            }

            return(item);
        }
Пример #4
0
        //delete all goals
        public static void DeleteAllGoals()
        {
            using (var db = new GoalDataContext())
            {
                foreach (var item in db.Goals)
                {
                    db.Goals.Remove(item);

                    db.SaveChanges();
                }
            }
        }
Пример #5
0
        public static async Task AddRecord <T>(T newRecord) where T : class
        {
            using (var db = new GoalDataContext())
            {
                db.Add <T>(newRecord);
                await db.SaveChangesAsync();

                if (typeof(T) == typeof(Transaction))
                {
                    var transaction = newRecord as Transaction;
                    await AddBalance(transaction);
                }
            }
        }
Пример #6
0
        private static async Task AddBalance(Transaction savedTransaction)
        {
            await Task.Factory.StartNew(async() =>
            {
                using (var db = new GoalDataContext())
                {
                    var goals = await db.Goals.ToListAsync();
                    var goal  = goals.SingleOrDefault(x => x.GoalId == savedTransaction.GoalId);

                    goal.Balance += savedTransaction.Amount;

                    await db.SaveChangesAsync();
                }
            });
        }
Пример #7
0
        public static async Task UpdateGoal(Goal UpdatedGoal)
        {
            using (var db = new GoalDataContext())
            {
                var goals = await db.Goals.ToListAsync();

                var goal = goals.FirstOrDefault(x => x.GoalId == UpdatedGoal.GoalId);

                if (goal != null)
                {
                    goal.Name       = UpdatedGoal.Name;
                    goal.Notes      = UpdatedGoal.Notes;
                    goal.SavingGoal = UpdatedGoal.SavingGoal;
                    await db.SaveChangesAsync();
                }
            }
        }
Пример #8
0
 //gets all the records
 public static List <T> GetTable <T>() where T : class
 {
     using (var db = new GoalDataContext())
         return(db.Set <T>().ToList());
 }