Пример #1
0
        /// <summary>
        /// 根據店號取得EC資料
        /// </summary>
        /// <returns></returns>
        public async Task <IEnumerable <IFECCUTF> > GetECDataAsync(string StoreNo)
        {
            try
            {
                Serilog.Log.Information("Start GetECDataAsync");
                result = await _cache.GetCacheByStoreno <IFECCUTF>(StoreNo);

                if (result == null)
                {
                    var data = await _db.IFECCUTFs.Where(a => a.StoreNo == StoreNo).ToListAsync();

                    if (data != null)
                    {
                        var  value     = JsonConvert.SerializeObject(data);
                        bool setStatus = await _cache.SetCacheByStoreNo(StoreNo, value);

                        if (setStatus == false)
                        {
                            result = await _db.IFECCUTFs.Where(a => a.StoreNo == StoreNo).ToListAsync();

                            Serilog.Log.Information("End GetECDataAsync:fail save data in redis");
                            return(result);
                        }
                        else
                        {
                            Serilog.Log.Information("End GetECDataAsync:success save data in redis");
                            result = await _cache.GetCacheByStoreno <IFECCUTF>(StoreNo);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Serilog.Log.Error(ex, $"GetECDataAsync In catch, time: {DateTime.Now}");
            }

            return(result);
            //if (_data != null && _data.ToList()[0].StoreNo == StoreNo)
            //    return _data;
            //else
            //{
            //    _data = await _db.IFECCUTFs.Where(a => a.StoreNo == StoreNo).ToListAsync();
            //    return _data;
            //}
        }