public CollectionResult <Drug> GetDrugsByParams(DrugsFilterParams parameters) { var appointments = GetAllDrugs(); FillDrugsQueryParams(parameters); appointments = appointments.Where(parameters.Expression); var totalCount = appointments.Count(); var result = appointments .OrderBy(x => x.Name) .Skip(parameters.Skip) .Take(parameters.Take) .AsNoTracking() .ToList(); var appointmentsResult = new CollectionResult <Drug> { Collection = result, TotalCount = totalCount }; return(appointmentsResult); }
public CollectionResult <DrugDto> GetDrugsByParams(DrugsFilterParams filterParams) { var items = _unitOfWork.DrugRepository.GetDrugsByParams(filterParams); var result = new CollectionResult <DrugDto> { TotalCount = items.TotalCount, Collection = AutoMapper.Mapper.Map <IEnumerable <Drug>, List <DrugDto> >(items.Collection) }; return(result); }
private void FillDrugsQueryParams(DrugsFilterParams filterParams) { var predicate = PredicateBuilder.New <Drug>(true); if (!string.IsNullOrWhiteSpace(filterParams.Term)) { predicate = predicate.And(t => t.Name.Contains(filterParams.Term) || t.Description.Contains(filterParams.Term)); } filterParams.Expression = predicate; }
public IActionResult GetDrugs([FromBody] DrugsFilterParams filterParams) { var items = _drugService.GetDrugsByParams(filterParams); return(Json(JsonResultData.Success(items))); }