public async Task <List <AppIngredients> > GetAllFilter(AppIngredientsQueryFilter filter) { List <AppIngredients> result = new List <AppIngredients>(); try { if (filter.Code != null && filter.Code.Length > 0) { result = await _context.AppIngredients.Where(x => x.Code.Trim().ToLower() == filter.Code.Trim().ToLower()).Skip((filter.PageNumber - 1) * filter.PageSize).Take(filter.PageSize).ToListAsync(); } else if (filter.Description != null && filter.Description.Length > 0) { result = await _context.AppIngredients.Where(x => x.Description.Trim().ToLower().Contains(filter.Description.Trim().ToLower())).Skip((filter.PageNumber - 1) * filter.PageSize).Take(filter.PageSize).ToListAsync(); } else if (filter.SearchText != null && filter.SearchText.Length > 0) { result = await _context.AppIngredients.Where(x => x.Description.Trim().ToLower().Contains(filter.SearchText.Trim().ToLower()) || x.Code.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.AppIngredients.Skip((filter.PageNumber - 1) *filter.PageSize).Take(filter.PageSize).ToListAsync(); } return(result); } catch (Exception e) { var a = e.InnerException.Message; return(result); } }
public async Task <ApiResponse <List <AppIngredientsGetDto> > > GetAllFilter(AppIngredientsQueryFilter filter) { filter.PageNumber = filter.PageNumber == 0 ? _paginationOptions.DefaultPageNumber : filter.PageNumber; filter.PageSize = filter.PageSize == 0 ? _paginationOptions.DefaultPageSize : filter.PageSize; List <AppIngredientsGetDto> resultDto = new List <AppIngredientsGetDto>(); Metadata metadata = new Metadata { IsValid = true, Message = "" }; ApiResponse <List <AppIngredientsGetDto> > response = new ApiResponse <List <AppIngredientsGetDto> >(resultDto); try { List <AppIngredients> appIngredients = await _unitOfWork.AppIngredientsRepository.GetAllFilter(filter); if (appIngredients != null) { List <AppIngredientsGetDto> appIngredientsDto = _mapper.Map <List <AppIngredientsGetDto> >(appIngredients); foreach (AppIngredientsGetDto item in appIngredientsDto) { AppUnits AppUnitsFind = await _appUnitsService.GetById(item.AppUnitId); if (AppUnitsFind != null) { AppUnitsGetDto appUnitsGetDto = _mapper.Map <AppUnitsGetDto>(AppUnitsFind); item.AppUnitsGetDto = appUnitsGetDto; } MtrTipoMoneda MtrTipoMonedaFind = await _mtrTipoMonedaService.GetById((long)item.PrymaryMtrMonedaId); if (MtrTipoMonedaFind != null) { MtrTipoMonedaDto mtrTipoMonedaDto = _mapper.Map <MtrTipoMonedaDto>(MtrTipoMonedaFind); item.PrymaryMtrMonedaDto = mtrTipoMonedaDto; } MtrTipoMonedaFind = await _mtrTipoMonedaService.GetById((long)item.SecundaryMtrMonedaId); if (MtrTipoMonedaFind != null) { MtrTipoMonedaDto mtrTipoMonedaDto = _mapper.Map <MtrTipoMonedaDto>(MtrTipoMonedaFind); item.SecundaryMtrMonedaDto = mtrTipoMonedaDto; } } response.Data = appIngredientsDto; 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); } }
public async Task <IActionResult> GetAllAppIngredients(AppIngredientsQueryFilter filters) { var response = await _appIngredientsService.GetAllFilter(filters); return(Ok(response)); }