예제 #1
0
        /// <summary>
        /// 根據店號、頁數、排序取得EC資料並顯示在畫面上
        /// </summary>
        /// <param name="storeNo">店號</param>
        /// <param name="page">目前頁次</param>
        /// <param name="sort">排序方式</param>
        /// <returns></returns>
        public async Task <IActionResult> GetAll(string storeNo, int page = 1, ECSort sort = ECSort.InDate)
        {
            ECListViewModel vm    = new ECListViewModel();
            StoreAndSort    param = new StoreAndSort
            {
                StoreNo = storeNo,
                Sort    = sort
            };

            //if(data==null || data.First().StoreNo != storeNo||eCSort!=sort)
            if (data == null || data.First().StoreNo != param.StoreNo || eCSort != param.Sort)
            {
                // eCSort = sort;
                eCSort = param.Sort;
                //data = await _ecRepo.GetECAsync(SD.ECChkAPIPath + "GetAll?storeno=" + storeNo, sort);
                data = await _ecRepo.GetECAsync(SD.ECChkAPIPath + "GetAll", param);
            }

            //放入EC資料至ViewModel
            vm.ECList = data.ToList();
            var count = vm.ECList.Count();

            //頁數資料
            vm.PagingInfo = new PagingInfo
            {
                CurrentPage  = page,
                ItemsPerPage = PageSize,
                TotalItems   = count,
                //eCSort = sort
                eCSort = param.Sort
            };
            //當頁顯示EC資料
            vm.ECList = vm.ECList.Skip((vm.PagingInfo.CurrentPage - 1) * PageSize).Take(PageSize).ToList();
            return(View(vm));
        }
예제 #2
0
        /// <summary>
        /// 取得EC資料
        /// </summary>
        /// <param name="url"></param>
        /// <param name="sort"></param>
        /// <returns></returns>
        //public async Task<IEnumerable<IFECCUTF>> GetECAsync(string url,ECSort sort=ECSort.InDate)
        public async Task <IEnumerable <IFECCUTF> > GetECAsync(string url, StoreAndSort param)
        {
            var request = new HttpRequestMessage(HttpMethod.Post, url);
            IEnumerable <IFECCUTF> obj;

            //request.Content = new StringContent(
            //    JsonConvert.SerializeObject(sort), Encoding.UTF8, "application/json");
            request.Content = new StringContent(
                JsonConvert.SerializeObject(param), Encoding.UTF8, "application/json");

            var client = _clientFactory.CreateClient();
            //送出請求
            HttpResponseMessage response = await client.SendAsync(request);

            //若回傳狀態201,代表成功
            if (response.StatusCode == HttpStatusCode.OK)
            {
                //取得回覆內容,在反序列化回去string
                var jsonString = await response.Content.ReadAsStringAsync();

                obj = JsonConvert.DeserializeObject <IEnumerable <IFECCUTF> >(jsonString);
                return(JsonConvert.DeserializeObject <IEnumerable <IFECCUTF> >(jsonString));
            }
            else
            {
                var msg = response.RequestMessage;
                return(null);
            }
        }
예제 #3
0
        [ProducesDefaultResponseType] //其他沒包括在上述設定ProducesResponseType的狀態會使用此屬性
        //public IActionResult GetAll(string StoreNo, [FromBody] ECSort sort = ECSort.InDate)
        public IActionResult GetAll([FromBody] StoreAndSort param)
        {
            try
            {
                Serilog.Log.Information("Start GetAll");
                if (param == null)
                {
                    Serilog.Log.Warning("End GetAll:No content");
                    return(NoContent());
                }

                //從Db根據店號取得EC資料
                var objList = _ecRepo.GetECDataAsync(param.StoreNo).Result;
                if (objList == null || objList.Count() == 0)
                {
                    return(NotFound());
                }

                //將資料mapping到IFECCUTFDto
                var objDto = new List <IFECCUTFDto>();
                foreach (var item in objList)
                {
                    objDto.Add(_mapper.Map <IFECCUTFDto>(item));
                }

                //取得排序後的EC資料
                ECService service = new ECService();
                var       objShow = service.SortECData(objDto, param.Sort);
                Serilog.Log.Information("End GetAll");
                return(Ok(objShow));
            }
            catch (Exception ex)
            {
                Serilog.Log.Error($"End GetAll:{ex.Message}");
                return(StatusCode(500, ModelState));
            }
        }