コード例 #1
0
        public async Task <IEnumerable <Category> > GetCategoriesTrAsync(string orderBy, bool showTrs)
        {
            orderBy = orderBy.ToLower();
            if (!allowedOrderByQueries.Contains(orderBy))
            {
                throw new InvalidOperationException($"Invalid \" {orderBy} \" orderBy query param. The allowed values are {string.Join(",", allowedOrderByQueries)}");
            }

            var CategoriesTrEntities = await CategoriesTrRepository.GetCategoriesTr(orderBy, showTrs);

            var res = mapper.Map <IEnumerable <Category> >(CategoriesTrEntities);

            for (int i = 0; i < res.Count(); i++)
            {
                res.ElementAt(i).CantProducts = res.ElementAt(i).products.Count();
                res.ElementAt(i).CantTrs      = res.ElementAt(i).trs.Count();
                if (!showTrs)
                {
                    res.ElementAt(i).products = new List <Product>();
                    res.ElementAt(i).trs      = new List <Tr>();
                }
            }
            return(res);
        }