示例#1
0
        public IHttpActionResult PostQuery(JObject jsonData)
        {
            var result   = new TransferObj();
            var postData = ((dynamic)jsonData);
            var filtered = ((JObject)postData.filtered).ToObject <FilterObj <KhachHangViewModel.Search> >();
            var paged    = ((JObject)postData.paged).ToObject <PagedObj <KHACHHANG> >();
            var unitCode = string.IsNullOrEmpty(filtered.PARENT_UNITCODE) ? filtered.UNITCODE : filtered.PARENT_UNITCODE;
            var query    = new QueryBuilder
            {
                Take   = paged.ItemsPerPage,
                Skip   = paged.FromItem - 1,
                Filter = new QueryFilterLinQ()
                {
                    Property = ClassHelper.GetProperty(() => new KHACHHANG().UNITCODE),
                    Method   = FilterMethod.EqualTo,
                    Value    = unitCode
                },
                Orders = new List <IQueryOrder>()
                {
                    new QueryOrder()
                    {
                        Field  = ClassHelper.GetPropertyName(() => new KHACHHANG().MAKHACHHANG),
                        Method = OrderMethod.ASC
                    }
                }
            };

            try
            {
                var filterResult = _service.Filter(filtered, query);
                if (!filterResult.WasSuccessful)
                {
                    return(NotFound());
                }
                result.Data   = filterResult.Value;
                result.Status = true;
                return(Ok(result));
            }
            catch (Exception)
            {
                return(InternalServerError());
            }
        }