public static Account GetAccount(int? id, int? companyId, bool forceSqlLoad) { var cache = new CacheWrapper(); var res = cache.GetFromList(CacheKey, new Account() { Id = id }, companyId); if (res == null || forceSqlLoad) { //load from DB res = AccountsDataAdapter.GetAccount(id, companyId); //save to cache //if (res == null) // not found in cache->add // cache.AddToList<Account>(CacheKey, res, companyId); //else // cache.UpdateList(CacheKey, res, companyId); } return res; }
public virtual FieldRule GetRule(int? id, int? userId, bool forceSqlLoad) { var cache = new CacheWrapper(); var res = cache.GetFromList(CacheKey, new FieldRule() { Id = id }, userId); if (res == null || forceSqlLoad) { //load from DB res = RulesDataAdapter.GetRule(id, userId); //save to cache /*if (res == null) // not found in cache->add cache.AddToList<FieldRule>(CacheKey, res, userId); else cache.UpdateList(CacheKey, res, userId);*/ } return res; }
public virtual Transaction GetTransaction(int? id, int? companyId, bool forceSqlLoad) { var cache = new CacheWrapper(); var res = cache.GetFromList(CacheKey, new Transaction { Id = id }, companyId); if (res == null || forceSqlLoad) { bool inCache = res != null; //load from DB res = TransactionsDataAdapter.GetTransaction(id, companyId); //res = new Transaction() { Description = "Test", Category = "Dinner", Amount = 100.20M, Id = 1, Date = DateTime.Now }; //save to cache //if (!inCache) // not found in cache->add // cache.AddToList<Transaction>(CacheKey, res, companyId); //else // cache.UpdateList(CacheKey, res, companyId); } return res; }
public virtual int ChangeBalance(int? accountId, int? companyId, decimal value) { var res = AccountsDataAdapter.ChangeBalance(accountId, companyId, value); var cache = new CacheWrapper(); if (res == 0) { Account account = cache.GetFromList(CacheKey, new Account() { Id = accountId }, companyId); if (account != null) { account.Balance = account.Balance + value; cache.UpdateList(CacheKey, account, companyId); } } return res; }