Пример #1
0
        public virtual async Task Delete(int id)
        {
            try
            {
                var model = _cache?.Find(id.ToString());

                if (model == null)
                {
                    model = await Get(id);
                }
                else
                {
                    _cache?.Delete(id.ToString());
                }
                if (model != null)
                {
                    _db.Remove(model);
                }
                Save();
            }
            catch (Exception ext)
            {
                throw new Exception("", ext);
            }
        }
Пример #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="id"></param>
        /// <param name="lineNumber"></param>
        /// <param name="caller"></param>
        /// <returns></returns>
        public T Get(string id, [CallerLineNumber] int lineNumber = 0, [CallerMemberName] string caller = null)
        {
            var result = _cache?.Find(id);

            if (result != null)
            {
                return(result);
            }
            return(_db.Find(m => m.Id == id).FirstOrDefault());
        }
Пример #3
0
        public T Get(int id, [CallerLineNumber] int lineNumber = 0, [CallerMemberName] string caller = null)
        {
            Stopwatch watch = new Stopwatch();

            try
            {
                watch.Start();
                T item = null;

                item = _cache?.Find(id.ToString());
                if (item != null)
                {
                    return(item);
                }
                item = _dbSet.Find(id);
                watch.Stop();
                Logging("Get", watch.ElapsedMilliseconds, lineNumber, caller, id);
                return(item);
            }
            catch (Exception ext)
            {
                watch.Stop();
                ErrorLogging("AddAsync Error", watch.ElapsedMilliseconds, id, ext, caller, lineNumber);
                return(null);
            }
        }
Пример #4
0
        public virtual T Get(int id, [CallerLineNumber] int lineNumber = 0, [CallerMemberName] string caller = null)
        {
            T item = null;

            item = _cache?.Find(id.ToString());
            if (item != null)
            {
                return(item);
            }
            item = _dbSet.Find(id);
            return(item);
        }
Пример #5
0
        private T GetFromCache(string parameters, bool expired = false)
        {
            var item = _cacheRepository.Find(GetType().Name, parameters, expired);

            if (item == null)
            {
                return(null);
            }

            foreach (var operation in _operations)
            {
                if (operation.GetType().Name == item.Operation)
                {
                    return(JsonConvert.DeserializeObject <T>(item.Result));
                }
            }

            return(default(T));
        }
Пример #6
0
 //TODO finish
 private T GetByCache(int id)
 {
     return(_cache?.Find(id.ToString()));
 }