Exemplo n.º 1
0
        public async Task <IActionResult> GetAll()
        {
            List <Category> categories = await db.Categories
                                         .AsNoTracking()
                                         .ToListAsync();

            //map to response
            CategoryGetAllResponse categoryGetAllResponse = CategoryMapper.MapFromCategoriesToCategoryGetAllResponse(categories);

            return(Ok(categoryGetAllResponse));
        }
        //get all
        public static CategoryGetAllResponse MapFromCategoriesToCategoryGetAllResponse(List <Category> categories)
        {
            CategoryGetAllResponse categoryGetAllResponse = new CategoryGetAllResponse
            {
                Entities = EntityType.Categories,
                CategoryResponseIndividuals = new List <CategoryResponseIndividual>()
            };

            foreach (var category in categories)
            {
                var categoryResponseIndividual = MapFromCategoryToCategoryResponseIndividual(category);
                categoryGetAllResponse.CategoryResponseIndividuals.Add(categoryResponseIndividual);
            }
            return(categoryGetAllResponse);
        }