public async Task <TResponse <PageResult <ProductUnitModel> > > GetPaging(int userId,
                                                                                  GetProductUnitPageModel request,
                                                                                  int permissionId)
        {
            try
            {
                var checkValid = await _userService.CheckPermission(userId,
                                                                    permissionId);

                if (checkValid.IsSuccess)
                {
                    var productUnits = await _productUnitCacheService.GetList();

                    if (productUnits != null)
                    {
                        var result = productUnits.Where(c => c.Name.IsContainsEx(request.Name))
                                     .OrderByEx(request.ColumnOrder,
                                                request.SortDir)
                                     .Select(c => new ProductUnitModel(c));
                        return(await Ok(new PageResult <ProductUnitModel>(request.Page,
                                                                          request.PageSize,
                                                                          result.Count(),
                                                                          result.ToPageResult(request))));
                    }

                    return(await Ok(new PageResult <ProductUnitModel>(request.Page,
                                                                      request.PageSize,
                                                                      0,
                                                                      new List <ProductUnitModel>())));
                }

                return(await Fail <PageResult <ProductUnitModel> >(checkValid.Message));
            }
            catch (Exception exception)
            {
                return(await Fail <PageResult <ProductUnitModel> >(exception));
            }
        }
Example #2
0
 public async Task <ActionResult <PageResult <ProductUnitModel> > > GetPaging([FromQuery] GetProductUnitPageModel request)
 {
     return(Ok(await _productUnitService.GetPaging(await GetUserId(),
                                                   request,
                                                   GetPermissionId())));
 }