Beispiel #1
0
        public IHttpActionResult PostQuery(JObject jsonData)
        {
            var result   = new TransferObj();
            var postData = ((dynamic)jsonData);
            var filtered = ((JObject)postData.filtered).ToObject <FilterObj <NguoiDungViewModel.Search> >();
            var paged    = ((JObject)postData.paged).ToObject <PagedObj <NGUOIDUNG> >();
            var unitCode = _service.GetCurrentUnitCode();
            var query    = new QueryBuilder
            {
                Take   = paged.ItemsPerPage,
                Skip   = paged.FromItem - 1,
                Filter = new QueryFilterLinQ()
                {
                    SubFilters = new List <IQueryFilter>()
                    {
                        new QueryFilterLinQ()
                        {
                            Property = ClassHelper.GetProperty(() => new NGUOIDUNG().UNITCODE),
                            Method   = FilterMethod.StartsWith,
                            Value    = unitCode
                        },
                        new QueryFilterLinQ()
                        {
                            Property = ClassHelper.GetProperty(() => new NGUOIDUNG().USERNAME),
                            Method   = FilterMethod.NotEqualTo,
                            Value    = "admin"
                        }
                    },
                    Method = FilterMethod.And
                },
                Orders = new List <IQueryOrder>()
                {
                    new QueryOrder()
                    {
                        Field  = ClassHelper.GetPropertyName(() => new NGUOIDUNG().USERNAME),
                        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());
            }
        }