Ejemplo n.º 1
0
        public ActionResult ShowTeamTopic(int topicId)
        {
            TopicWithCommentsViewModel model = this.service.GetTopicById(topicId);

            this.ValidateIfCurrentUserIsMemberOfTeam(model.TeamId);
            return(this.View(model));
        }
Ejemplo n.º 2
0
        private TopicWithCommentsViewModel MapTopicWithCommentsViewModelFromTopic(Topic topic)
        {
            var config = new MapperConfiguration(cfg =>
            {
                cfg.CreateMap <Comment, CommentViewModel>()
                .ForMember(dto => dto.Author, conf => conf.MapFrom(x => x.Author.UserName))
                .ForMember(dto => dto.Content, conf => conf.MapFrom(x => x.Content))
                .ForMember(dto => dto.CreatedOn, conf => conf.MapFrom(x => x.CreatedOn));
            });
            var mapper = config.CreateMapper();
            IEnumerable <CommentViewModel> commentModels = topic.Comments.Select(mapper.Map <CommentViewModel>);

            var topicModel = new TopicWithCommentsViewModel()
            {
                Id       = topic.Id,
                Title    = topic.Title,
                Comments = commentModels,
                TeamId   = topic.Team.Id
            };

            return(topicModel);
        }