Exemplo n.º 1
0
        public async Task <IActionResult> GetListByCategory([FromRoute] string category, [FromQuery] int page = 1)
        {
            var cat = await _categoryService.GetBySlugAsync(category);

            if (cat == null)
            {
                return(NotFound());
            }

            var categoryModel = _categoryFactory.ToModel(cat, new Models.CategoryModel());

            return(await GetPostsAsync(new GetPostListRequestModel()
            {
                Page = page,
                Category = categoryModel,
            }));
        }
Exemplo n.º 2
0
        public PostModel ToModel(Post entity, PostModel model)
        {
            model = _mapper.Map(entity, model);

            if (entity.User != null)
            {
                model.User = _userFactory.ToModel(entity.User, new UserModel());
            }

            if (entity.Categories != null)
            {
                model.Categories = entity.Categories.Select(t => _categoryFactory.ToModel(t.Category, new CategoryModel())).ToArray();
            }

            if (entity.Tags != null)
            {
                model.Tags = entity.Tags.Select(t => t.Tags.Name).ToArray();
            }

            return(model);
        }
        public async Task <IEnumerable <CategoryListItemModel> > GetListAsync()
        {
            var list = await _categoryService.GetListAsync();

            return(list.Select(t => _categoryFactory.ToModel(t, new CategoryListItemModel())).ToList());
        }