コード例 #1
0
        public async Task <ActionResult <IEnumerable <Drug> > > GetAll([FromQuery] DrugParams drugParams)
        {
            var drugs = await _uow.DrugRepository.GetDrugsAsync(drugParams);

            if (drugs != null)
            {
                Response.AddPaginationHeader(drugs.CurrentPage, drugs.PageSize,
                                             drugs.TotalCount, drugs.TotalPages);
                var model = _mapper.Map <IEnumerable <DrugDto> >(drugs);
                foreach (var d in model)
                {
                    if (d.PharmGroupId != null)
                    {
                        d.PharmGroup = _uow.PharmGroupRepository
                                       .Find(i => i.Id == d.PharmGroupId)
                                       .FirstOrDefault()
                                       .Name;
                    }
                    else
                    {
                        d.PharmGroupId = 0;
                        d.PharmGroup   = "undefined";
                    }

                    var ingredients = _uow.DrugActiveIngredientRepository
                                      .Get(u => u.DrugId == d.Id)
                                      .Select(u => u.ActiveIngredientId);
                }
                return(Ok(model));
            }
            ;

            return(BadRequest("Error occured during getting all drugs"));
        }
コード例 #2
0
        public async Task <PagedList <Drug> > GetDrugsAsync(DrugParams drugParameters)
        {
            IEnumerable <Drug> drugs = dbSet.AsEnumerable();

            if (drugParameters.PharmGroupId > 0)
            {
                drugs = drugs.Where(d => d.PharmGroupId == drugParameters.PharmGroupId);
            }

            if (!string.IsNullOrEmpty(drugParameters.DrugName))
            {
                drugs = drugParameters.Eng switch
                {
                    true => drugs.Where(b => b.NameEng.ToLower().Contains(drugParameters.DrugName.ToLower())),
                    false => drugs.Where(b => b.NameRus.ToLower().Contains(drugParameters.DrugName.ToLower()))
                };
            }

            drugs = drugParameters.Eng switch
            {
                true => drugs = drugParameters.AlphabeticalOrderAsc switch
                {
                    true => drugs.OrderBy(u => u.NameEng),
                    false => drugs.OrderByDescending(u => u.NameEng)
                },