コード例 #1
0
        public async Task <IActionResult> GetWithBlogsCount()
        {
            var categories = await _categoryService.GetAllWithCategoryBlogsAsync();

            List <CategoryWithBlogsCountDto> listCategory = new List <CategoryWithBlogsCountDto>();

            foreach (var item in categories)
            {
                CategoryWithBlogsCountDto dto = new CategoryWithBlogsCountDto();
                dto.CategoryName = item.Name;
                dto.CategoryId   = item.Id;
                dto.BlogsCount   = item.CategoryBlogs.Count;
                listCategory.Add(dto);
            }
            return(Ok(listCategory));
        }
コード例 #2
0
        public async Task <IActionResult> GetWithBlogsCount()
        {
            var categories = await _categoryService.GetAllCategoryWithBlogsCount();

            List <CategoryWithBlogsCountDto> listdto = new List <CategoryWithBlogsCountDto>();

            foreach (var cat in categories)
            {
                CategoryWithBlogsCountDto dto = new CategoryWithBlogsCountDto();
                dto.BlogsCount = cat.categoryBlogs.Count;
                dto.Id         = cat.Id;
                dto.Name       = cat.Name;
                listdto.Add(dto);
            }

            return(Ok(listdto));
        }
コード例 #3
0
        public async Task <IActionResult> GetWithCategryCount()
        {
            var categories = await categoryService.GetAllWithCategoryBlogsAsync();

            List <CategoryWithBlogsCountDto> models = new List <CategoryWithBlogsCountDto>();

            foreach (var item in categories)
            {
                var model = new CategoryWithBlogsCountDto();
                model.Name = item.Name;

                model.Id         = item.Id;
                model.BlogsCount = item.CategoryBlogs.Count();
                models.Add(model);
            }
            return(Ok(models));
        }
コード例 #4
0
        public async Task <IActionResult> GetWithBlogsCount()
        {
            var categories = await _categoryService.GetAllWithCategoryBlogsAsync();

            List <CategoryWithBlogsCountDto> categoryWithBlogsCountDto = new List <CategoryWithBlogsCountDto>();

            foreach (var category in categories)
            {
                CategoryWithBlogsCountDto dto = new CategoryWithBlogsCountDto
                {
                    CategoryId   = category.Id,
                    CategoryName = category.Name,
                    BlogsCount   = category.CategoryBlogs.Count
                };
                categoryWithBlogsCountDto.Add(dto);
            }
            return(Ok(categoryWithBlogsCountDto));
        }
コード例 #5
0
        public async Task <List <CategoryWithBlogsCountDto> > GetAllWithCategoryBlogsAsync()
        {
            var categories = await _categoryDal.GetAllWithCategoryBlogsAsync();

            var listCategory = new List <CategoryWithBlogsCountDto>();

            foreach (var category in categories)
            {
                var dto = new CategoryWithBlogsCountDto
                {
                    CategoryName = category.Name,
                    CategoryId   = category.Id,
                    BlogsCount   = category.CategoryBlogs.Count
                };

                listCategory.Add(dto);
            }

            return(listCategory);
        }