public DeviceListViewModel getListDevices(ParamGetListDevices param)
        {
            var returndata = new DeviceListViewModel();

            returndata.listDevices = new List <DeviceViewModel>();
            try
            {
                returndata.CountData   = _db.Devices.Count();
                returndata.listDevices = (from a in _db.Devices
                                          select new DeviceViewModel
                {
                    Id = a.Id,
                    IMEI = a.IMEI,
                    Model = a.Model,
                    SimCardNo = a.SimCardNo,
                    Enabled = a.Enabled,
                    CreatedDate = a.CreatedDate,
                    CreatedDateFormat = a.CreatedDate.ToString("dd MMM yyyy"),
                    CreatedBy = a.CreatedBy
                }).OrderBy(x => x.CreatedDate).Skip((param.page - 1) * param.itemPerPage).Take(param.itemPerPage).ToList();
                return(returndata);
            }
            catch (Exception ex)
            {
                _logger.Log(LogLevel.Critical, ex.Message.ToString());
                throw new ArgumentException(ex.Message);
            }
        }
        public async Task <IActionResult> DataTableDevices(IDataTablesRequest request, string param)
        {
            int oPage              = 1;
            int returnPageNumber   = 0;
            int returnTotalRecords = 0;

            try
            {
                if (request.Start > 0)
                {
                    oPage = (request.Start / 10) + 1;
                }

                var contentType    = "application/json";
                var dataParamToApi = new ParamGetListDevices();

                dataParamToApi.page        = oPage;
                dataParamToApi.itemPerPage = 10;

                ApiResult <ReturnGetListDevicesViewModel> resutlApi = new ApiResult <ReturnGetListDevicesViewModel>();
                _client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(contentType));

                var           dataParameter = JsonConvert.SerializeObject(dataParamToApi);
                StringContent contentData   = new StringContent(dataParameter, Encoding.UTF8, "application/json");

                resutlApi = await _client.PostAsync <ReturnGetListDevicesViewModel>($"{_apiConfig.ApiUrl}{_apiAliasConfig.GetDevicesPerPagging}", contentData);

                if (!resutlApi.isSuccessful)
                {
                    throw new ArgumentException(resutlApi.message);
                }

                var datafromApi = resutlApi.Payload.listDevices.AsQueryable();

                if (datafromApi.Any())
                {
                    returnPageNumber   = oPage;
                    returnTotalRecords = resutlApi.Payload.CountData;
                }

                #region Shorted
                IOrderedQueryable <DevicesViewModel> dataSorted = null;
                #endregion
                var response = DataTablesResponse.Create(request, returnPageNumber, returnTotalRecords, dataSorted != null ? dataSorted : datafromApi);

                return(new DataTablesJsonResult(response, true));
            }
            catch (Exception ex)
            {
                return(Json(new { error = ex.Message }));
            }
        }
Ejemplo n.º 3
0
        public JsonResult GetListDevices([FromBody] ParamGetListDevices param)
        {
            var returnData = new DeviceListViewModel();

            try
            {
                returnData = _facade.getListDevices(param);
                return(Json(new ApiResult <DeviceListViewModel>()
                {
                    isSuccessful = true, Payload = returnData
                }));
            }
            catch (Exception ex)
            {
                return(Json(new ApiResult <DeviceListViewModel>()
                {
                    isSuccessful = false, Payload = returnData, message = ex.Message
                }));
            }
        }