コード例 #1
0
        public async Task <List <AppProducts> > GetAllFilter(AppProdutsQueryFilter filter)
        {
            List <AppProducts> result = new List <AppProducts>();


            try
            {
                if (filter.Code != null && filter.Code.Length > 0)
                {
                    result = await _context.AppProducts.Where(x => x.Code.Trim().ToLower() == filter.Code.Trim().ToLower()).Skip((filter.PageNumber - 1) * filter.PageSize).Take(filter.PageSize).ToListAsync();
                }
                else if (filter.Description1 != null && filter.Description1.Length > 0)
                {
                    result = await _context.AppProducts.Where(x => x.Description1.Trim().ToLower().Contains(filter.Description1.Trim().ToLower())).Skip((filter.PageNumber - 1) * filter.PageSize).Take(filter.PageSize).ToListAsync();
                }
                else if (filter.Description2 != null && filter.Description2.Length > 0)
                {
                    result = await _context.AppProducts.Where(x => x.Description2.Trim().ToLower().Contains(filter.Description2.Trim().ToLower())).Skip((filter.PageNumber - 1) * filter.PageSize).Take(filter.PageSize).ToListAsync();
                }
                else if (filter.SearchText != null && filter.SearchText.Length > 0)
                {
                    if (filter.SubCategoria > 0)
                    {
                        result = await _context.AppProducts.Where(x => (x.AppSubCategoryId == filter.SubCategoria) && (x.Description1.Trim().ToLower().Contains(filter.SearchText.Trim().ToLower()) || x.Description2.Trim().ToLower().Contains(filter.SearchText.Trim().ToLower()) || x.Code.Trim().ToLower().Contains(filter.SearchText.Trim().ToLower()))).Skip((filter.PageNumber - 1) * filter.PageSize).Take(filter.PageSize).ToListAsync();
                    }
                    else
                    {
                        result = await _context.AppProducts.Where(x => x.Description1.Trim().ToLower().Contains(filter.SearchText.Trim().ToLower()) || x.Description2.Trim().ToLower().Contains(filter.SearchText.Trim().ToLower()) || x.Code.Trim().ToLower().Contains(filter.SearchText.Trim().ToLower())).Skip((filter.PageNumber - 1) * filter.PageSize).Take(filter.PageSize).ToListAsync();
                    }
                }

                else
                {
                    if (filter.SubCategoria > 0)
                    {
                        result = await _context.AppProducts.Where(x => x.AppSubCategoryId == filter.SubCategoria).Skip((filter.PageNumber - 1) * filter.PageSize).Take(filter.PageSize).ToListAsync();
                    }
                    else
                    {
                        result = await _context.AppProducts.Skip((filter.PageNumber - 1) *filter.PageSize).Take(filter.PageSize).ToListAsync();
                    }
                }


                return(result);
            }
            catch (Exception e)
            {
                var a = e.InnerException.Message;
                return(result);
            }
        }
コード例 #2
0
        public async Task <IActionResult> GetAllAppProducts(AppProdutsQueryFilter filters)
        {
            var response = await _appProductsService.GetAll(filters);

            return(Ok(response));
        }
コード例 #3
0
        public async Task <ApiResponse <List <AppProductsGetDto> > > GetAll(AppProdutsQueryFilter filters)
        {
            filters.PageNumber = filters.PageNumber == 0 ? _paginationOptions.DefaultPageNumber : filters.PageNumber;
            filters.PageSize   = filters.PageSize == 0 ? _paginationOptions.DefaultPageSize : filters.PageSize;

            List <AppProductsGetDto> resultDto = new List <AppProductsGetDto>();

            Metadata metadata = new Metadata
            {
                IsValid = true,
                Message = ""
            };
            ApiResponse <List <AppProductsGetDto> > response = new ApiResponse <List <AppProductsGetDto> >(resultDto);

            try
            {
                var appProducts = await _unitOfWork.AppProductsRepository.GetAllFilter(filters);

                if (appProducts != null)
                {
                    List <AppProductsGetDto> appProductsDto = _mapper.Map <List <AppProductsGetDto> >(appProducts);
                    foreach (var item in appProductsDto)
                    {
                        if (item.UrlImage == "" || item.UrlImage == null)
                        {
                            item.Link = _paginationOptions.UrlGetFiles + "NoImage.png";
                        }
                        else
                        {
                            item.Link = _paginationOptions.UrlGetFiles + item.UrlImage;
                        }

                        AppUnits AppUnitsFind = await _appUnitsService.GetById((int)item.AppUnitsId);

                        if (AppUnitsFind != null)
                        {
                            AppUnitsGetDto appUnitsGetDto = _mapper.Map <AppUnitsGetDto>(AppUnitsFind);
                            item.AppUnitsGetDto = appUnitsGetDto;
                        }

                        AppUnitsFind = await _appUnitsService.GetById((int)item.ProductionUnitId);

                        if (AppUnitsFind != null)
                        {
                            AppUnitsGetDto appUnitsGetDto = _mapper.Map <AppUnitsGetDto>(AppUnitsFind);
                            item.ProductionUnitGetDto = appUnitsGetDto;
                        }


                        MtrTipoMoneda MtrTipoMonedaFind = await _mtrTipoMonedaService.GetById((long)item.PrymaryMtrMonedaId);

                        if (MtrTipoMonedaFind != null)
                        {
                            MtrTipoMonedaDto mtrTipoMonedaDto = _mapper.Map <MtrTipoMonedaDto>(MtrTipoMonedaFind);
                            item.PrymaryMtrMonedaGetDto = mtrTipoMonedaDto;
                        }

                        MtrTipoMonedaFind = await _mtrTipoMonedaService.GetById((long)item.SecundaryMtrMonedaId);

                        if (MtrTipoMonedaFind != null)
                        {
                            MtrTipoMonedaDto mtrTipoMonedaDto = _mapper.Map <MtrTipoMonedaDto>(MtrTipoMonedaFind);
                            item.SecundaryMtrMonedaGetDto = mtrTipoMonedaDto;
                        }

                        AppSubCategory AppSubCategoryFind = await _appSubCategoryService.GetById((int)item.AppSubCategoryId);

                        if (AppSubCategoryFind != null)
                        {
                            AppSubCategoryGetDto appSubCategoryGetDto = _mapper.Map <AppSubCategoryGetDto>(AppSubCategoryFind);
                            item.AppSubCategoryGetDto = appSubCategoryGetDto;
                        }
                    }



                    response.Data = appProductsDto;
                    response.Meta = metadata;
                    return(response);
                }
                else
                {
                    metadata.IsValid = true;
                    metadata.Message = "No Data....";
                    response.Data    = null;
                    response.Meta    = metadata;
                    return(response);
                }
            }
            catch (Exception ex)
            {
                metadata.IsValid = false;
                metadata.Message = ex.InnerException.Message;
                response.Data    = null;
                response.Meta    = metadata;
                return(response);
            }
        }