public CountsDTO GetCounts()
        {
            var data = new CountsDTO
            {
                CategoriesCount  = this.categoryRepository.All().Count(),
                RecipesCount     = this.recipesRepository.All().Count(),
                ImagesCount      = this.imageRepository.All().Count(),
                IngredientsCount = this.ingredientRepository.All().Count(),
            };

            return(data);
        }
Exemplo n.º 2
0
        public async Task <Result <CountsDTO> > GetCounts(string userId)
        {
            var user = await _userManager.FindByIdAsync(userId);

            if (user == null)
            {
                return(Result <CountsDTO> .CreateFailed(
                           HttpStatusCode.NotFound, "User not found"));
            }
            var roles = await _userManager.GetRolesAsync(user);

            if (!roles.Contains("Admin"))
            {
                return(Result <CountsDTO> .CreateFailed(
                           HttpStatusCode.NotFound, "Has not Admin Role"));
            }

            var usersCount = await _context.Users.CountAsync();

            var counts = new CountsDTO();

            counts.Users = usersCount;
            return(Result <CountsDTO> .CreateSuccessful(counts));
        }