示例#1
0
        public static Post AsPost(this PostAuthorViewModel viewModel)
        {
            var post = (viewModel as PostOnlyViewModel).AsPost();

            post.User = viewModel.User.AsApplicationUser();
            return(post);
        }
 public IActionResult Put(int id, [FromBody] PostAuthorViewModel author)
 {
     if (ModelState.IsValid)
     {
         _authorService.Edit(author);
         return(Ok(author));
     }
     return(BadRequest(ModelState));
 }
示例#3
0
        public IActionResult Index(string id, PostSearchViewModel model)
        {
            if (model.PageIndex == 0)
            {
                model.PageIndex = 1;
            }
            if (model.PageSize == 0)
            {
                model.PageSize = 10;
            }

            IPagedList <Post> posts = _post.GetPostList(o => o.UserId == id).OrderByDescending(o => o.DateCreated).ToList().ToPagedList(model.PageIndex, model.PageSize);;

            IEnumerable <PostListViewModel> postList = _mapper.Map <IEnumerable <PostListViewModel> >(posts);
            // create an instance of StaticPagedList with the mapped IEnumerable and original IPagedList metadata
            IPagedList <PostListViewModel> postListViewModel = new StaticPagedList <PostListViewModel>(postList, posts.GetMetaData());

            foreach (var item in postListViewModel)
            {
                item.PostTagList = _mapper.Map <List <PostTag>, List <PostTagViewModel> >(_postTag.GetPostTagList(o => o.PostId == item.PostId));
                foreach (var postTag in item.PostTagList)
                {
                    postTag.TagName = _tag.GetTag(o => o.TagId == postTag.TagId).TagName;
                }
                item.CategoryName = _category.GetCategory(o => o.CategoryId == item.CategoryId).CategoryName;
            }

            var authorModel = new PostAuthorViewModel {
                PostList = postListViewModel
            };

            authorModel.UserName = _userManager.FindByIdAsync(id).Result.UserName;

            authorModel.CountUserPosts = _post.GetCountUserPosts(id);
            authorModel.CountUserViews = _post.GetCountUserViews(id).Value;

            return(View(authorModel));
        }
示例#4
0
 public IActionResult Post([FromBody] PostAuthorViewModel author)
 {
     _authorService.Add(author);
     return(Ok());
 }
示例#5
0
 private Author ToAuthor(PostAuthorViewModel authorViewModel)
 {
     return(Mapper.Map <PostAuthorViewModel, Author>(authorViewModel));
 }
示例#6
0
 public void Edit(PostAuthorViewModel author)
 {
     _authorRepository.Update(ToAuthor(author));
 }
示例#7
0
 public void Add(PostAuthorViewModel author)
 {
     _authorRepository.Add(ToAuthor(author));
 }
        public void Add(PostAuthorViewModel authorView)
        {
            Author publisher = Mapper.Map <PostAuthorViewModel, Author>(authorView);

            _authorRepository.Add(publisher);
        }