예제 #1
0
        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);
        }
예제 #3
0
        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;
        }
예제 #4
0
        public IActionResult GetDrugs([FromBody] DrugsFilterParams filterParams)
        {
            var items = _drugService.GetDrugsByParams(filterParams);

            return(Json(JsonResultData.Success(items)));
        }