public async Task <ApiResponse <List <ProductShelfListViewModel> > > GetAll(SearchProductShelfViewModel viewModel)
        {
            ApiResponse <List <ProductShelfListViewModel> > response = new ApiResponse <List <ProductShelfListViewModel> >();

            try
            {
                var count = UnitOfWork.Repository <ProductShelf>().Query().Count(x => !x.IsDeleted);
                Expression <Func <ProductShelf, bool> > queryPredicate = (x) => x.Name.Contains(viewModel.FilterBy) ||
                                                                         x.CreatedOn >= viewModel.ToDate || x.CreatedOn <= viewModel.FromDate;

                var result = (await this.GetAllAsync(viewModel.PageIndex, viewModel.PageSize, c => c.Id, queryPredicate, OrderBy.Ascending))
                             .OrderBy(b => b.Id).Select(source => new ProductShelfListViewModel
                {
                    Name        = source.Name,
                    Description = source.Description,
                    TotalCount  = count,
                    Id          = source.Id.ToString(),
                }).ToList();
                response.Payload     = result;
                response.Code        = ApiResponseCodes.OK;
                response.Description = ApiResponseCodes.OK.ToString();
                return(response);
            }
            catch (Exception ex)
            {
                response.Payload     = null;
                response.Code        = ApiResponseCodes.ERROR;
                response.Description = ex.Message;
                return(response);
            }
        }
示例#2
0
        //[Route("GetAllCategory")]

        public async Task <IActionResult> GetAll([FromBody] SearchProductShelfViewModel viewModel)
        {
            if (viewModel.PageIndex == -1 || viewModel.PageSize == -1)
            {
                return(this.ApiResponse <string>(null, $"{viewModel.PageIndex} or {viewModel.PageSize} can not be -1", ApiResponseCodes.INVALID_REQUEST));
            }

            var result = await _productShelftService.GetAll(viewModel);

            if ((result.Code != ApiResponseCodes.OK))
            {
                return(base.ApiResponse <string>(null, result.Description,
                                                 ApiResponseCodes.EXCEPTION, 1));
            }
            if (result.Payload == null)
            {
                return(this.ApiResponse <List <ProductShelfListViewModel> >(result.Payload, "Record not Found.", ApiResponseCodes.NOT_FOUND));
            }
            return(this.ApiResponse <List <ProductShelfListViewModel> >(result.Payload, "successful.", ApiResponseCodes.OK));
        }