Exemplo n.º 1
0
        public ActionResult Index()
        {
            var userId = User.Identity.GetUserId();

            IEnumerable <UserTopicViewModel> topics = uow.TopicRepository
                                                      .Get(null, null, "Subscriptions,Posts,Posts.Author")
                                                      .ToList()
                                                      .Select(t => TopicMapper.Map(t, userId, t.Posts));

            return(View(topics.ToList()));
        }
Exemplo n.º 2
0
        public ActionResult Index()
        {
            var topics = uow.TopicRepository
                         .Get(includeProperties: "Posts,Posts.Author,Subscriptions")
                         .ToList();

            if (currentUser.IsLoggedIn())
            {
                return(RedirectToAction("Index", "NewsFeed"));
            }
            else
            {
                return(View(topics.Select(t => TopicMapper.Map(t)).ToList()));
            }
        }
Exemplo n.º 3
0
        public ActionResult Details(string name, string query)
        {
            if (query == null)
            {
                query = "";
            }

            query = query.ToLower();

            var topic = uow.TopicRepository
                        .Get(
                filter: t => t.Name.ToLower() == name,
                includeProperties: "Subscriptions,Posts.Author"
                )
                        .FirstOrDefault();


            if (topic == null)
            {
                throw new TopicNotFoundException(name);
            }

            Expression <Func <PostModel, bool> > postsFilter = p =>
                                                               p.TopicName.ToLower() == name.ToLower() &&
                                                               (p.Title.ToLower().Contains(query) ||
                                                                p.Content.ToLower().Contains(query) ||
                                                                p.Author.UserName.ToLower().Contains(query) ||
                                                                p.TopicName.ToLower().Contains(query));

            if (currentUser.IsLoggedIn())
            {
                var userId = User.Identity.GetUserId();
                var user   = uow.UserRepository.GetByID(userId);

                var posts = uow.PostRepository.Get(postsFilter, p => p.OrderByDescending(post => post.PostedAt), "Author");


                return(View(TopicMapper.Map(topic, userId, posts.ToList())));
            }


            return(View(TopicMapper.Map(new Entities.Topic.TopicModel
            {
                Posts = uow.PostRepository.Get(postsFilter).Where(p => p.TopicName == name).ToList(),
                Name = name,
                Subscriptions = topic.Subscriptions
            })));
        }