예제 #1
0
        public virtual async Task <ActionResult <PaginationModel <TRead> > > Get()
        {
            bool isFromDate = DateTime.TryParse(Request.Query[MixRequestQueryKeywords.FromDate], out DateTime fromDate);
            bool isToDate   = DateTime.TryParse(Request.Query[MixRequestQueryKeywords.ToDate], out DateTime toDate);

            int.TryParse(Request.Query[MixRequestQueryKeywords.PageIndex], out int pageIndex);
            bool isDirection = Enum.TryParse(Request.Query[MixRequestQueryKeywords.Direction], out DisplayDirection direction);
            bool isPageSize  = int.TryParse(Request.Query[MixRequestQueryKeywords.PageSize], out int pageSize);

            RequestPaging request = new RequestPaging()
            {
                PageIndex = pageIndex,
                PageSize  = isPageSize ? pageSize : 100,
                OrderBy   = Request.Query[MixRequestQueryKeywords.OrderBy].ToString().ToTitleCase(),
                Direction = direction
            };

            RepositoryResponse <PaginationModel <TRead> > getData = await _repo.GetModelListAsync(
                request.OrderBy, request.Direction, request.PageSize, request.PageIndex, null, null).ConfigureAwait(false);

            if (getData.IsSucceed)
            {
                return(Ok(getData.Data));
            }
            else
            {
                return(BadRequest(getData.Errors));
            }
        }
예제 #2
0
        public virtual async Task <ActionResult <PaginationModel <TView> > > Get()
        {
            bool isFromDate = DateTime.TryParse(Request.Query[MixRequestQueryKeywords.FromDate], out DateTime fromDate);
            bool isToDate   = DateTime.TryParse(Request.Query[MixRequestQueryKeywords.ToDate], out DateTime toDate);

            int.TryParse(Request.Query[MixRequestQueryKeywords.PageIndex], out int pageIndex);
            bool isDirection = Enum.TryParse(Request.Query[MixRequestQueryKeywords.Direction], out Heart.Enums.DisplayDirection direction);
            bool isPageSize  = int.TryParse(Request.Query[MixRequestQueryKeywords.PageSize], out int pageSize);

            RequestPaging request = new RequestPaging()
            {
                PageIndex = pageIndex,
                PageSize  = isPageSize ? pageSize : 100,
                OrderBy   = Request.Query[MixRequestQueryKeywords.OrderBy].ToString().ToTitleCase(),
                Direction = direction
            };
            Expression <Func <TModel, bool> >             predicate = null;
            RepositoryResponse <PaginationModel <TView> > getData   = null;

            if (!string.IsNullOrEmpty(_lang))
            {
                predicate = ReflectionHelper.GetExpression <TModel>(MixQueryColumnName.Specificulture, _lang, Heart.Enums.ExpressionMethod.Eq);
                getData   = await _repo.GetModelListByAsync(
                    predicate,
                    request.OrderBy, request.Direction,
                    request.PageSize, request.PageIndex, null, null)
                            .ConfigureAwait(false);
            }
            else
            {
                getData = await _repo.GetModelListAsync(
                    request.OrderBy, request.Direction, request.PageSize, request.PageIndex, null, null).ConfigureAwait(false);
            }

            if (getData.IsSucceed)
            {
                return(Ok(getData.Data));
            }
            else
            {
                return(BadRequest(getData.Errors));
            }
        }