public async Task <List <CodeTransactionDTO> > TransactionsCodes() { List <CodeTransactionDTO> transactionsCodeCached = _cache.GetValue <List <CodeTransactionDTO> >(KEY_CACHE_CODES); if (transactionsCodeCached == null) { List <CodeTransactionDTO> codesTransactionsBD = (await(from MCodeTransaction codes in _contextDB.MCodeTransaction.AsNoTracking() select codes) .ToListAsync()) .Select(x => x.ToCodeTransactionDTO()) .ToList(); if (!_cache.SetValue(KEY_CACHE_CODES, codesTransactionsBD)) { _log.LogWarning($"{nameof(TransactionsCodes)} could not be cached!"); } return(codesTransactionsBD); } else { return(_cache.GetValue <List <CodeTransactionDTO> >(KEY_CACHE_CODES)); } }
public async Task <List <TransactionDTO> > Transactions(int year, int month) { string keyCacheYearMonth = BuildKeyCache(year, month); List <TransactionDTO> transactionsCached = _cache.GetValue <List <TransactionDTO> >(keyCacheYearMonth); if (transactionsCached == null) { bool loadCompleteYear = month == 0; List <TransactionDTO> transactionsBD = (await(from TransactionOutlay t in _contextDB.TransactionOutlay .AsNoTracking() .Include(x => x.TypeTransaction) .Include(x => x.CodeTransaction) select t) .ToListAsync()) .Where(t => { DateTime dateParsed = t.DateTransaction.ToDateTime(); if (loadCompleteYear) { return(dateParsed.Year == year); } else { return(dateParsed.Year == year && dateParsed.Month == month); } }) .Select(x => x.ToTransactionDTO()) .ToList(); if (!_cache.SetValue(keyCacheYearMonth, transactionsBD)) { _log.LogWarning($"{nameof(Transactions)} could not be cached!"); } return(transactionsBD); } else { return(transactionsCached); } }