Ejemplo n.º 1
0
        public static PostListViewModel ToOverview(this PostsData <PostsNode> source, string baseCategory = "")
        {
            var posts = new List <PostOverview>();

            foreach (var edge in source.EdgeList.Edges)
            {
                var ov = new PostOverview();
                ov.Id         = edge.Node.Id;
                ov.Cursor     = edge.Cursor;
                ov.AuthorInfo = $"{edge.Node.Author.ToAuthorInfo()} am {edge.Node.Date.ToShortDateString()}";
                ov.Categories = edge.Node.Categories.ToCategoryList(baseCategory);
                ov.Excerpt    = edge.Node.Excerpt;
                ov.IsSticky   = edge.Node.IsSticky;
                ov.Title      = edge.Node.Title;
                ov.Date       = edge.Node.Date;
                ov.Link       = $"/post/{ov.Id}";
                posts.Add(ov);
            }

            var vm = new PostListViewModel
            {
                Posts    = posts,
                PageInfo = source.EdgeList.PageInfo
            };

            return(vm);
        }
Ejemplo n.º 2
0
        //
        // GET: /Post/
        public ActionResult Index(string type, string search = null)
        {
            var controller = new SubMenuModel();

            controller.Items.Add(new MenuItem("Latest Posts", "Post", "Index", true));
            controller.Items.Add(new MenuItem("Not Answered", "Post", "NotAnswered"));
            var posts = this.PostDB.All()
                        .Where(post => search == null ||
                               "title" == type && post.Title.ToLower().Contains(search.ToLower()) ||
                               "user" == type && post.Author.Username.ToLower().Contains(search.ToLower()) ||
                               "text" == type && post.Text.ToLower().Contains(search.ToLower()))
                        .OrderByDescending(post => post.TimeOfPost)
                        .ToList();
            PostOverview model = new PostOverview();

            model.SubMenu = controller;
            model.Posts.AddRange(posts.Select(post => new PostLight(post)));
            return(View(model));
        }
Ejemplo n.º 3
0
 //
 // GET: /User/Stream
 public ActionResult Stream(string type, string search = null)
 {
     if (true != User.Identity.IsAuthenticated)
     {
         return(RedirectToAction("Login", "Account"));
     }
     else
     {
         var controller = new SubMenuModel();
         controller.Items.Add(new MenuItem("Stream", "User", "Stream", true));
         controller.Items.Add(new MenuItem("Members Followed", "User", "StreamUsers"));
         controller.Items.Add(new MenuItem("Tags Followed", "User", "StreamTags"));
         controller.Items.Add(new MenuItem("My Posts", "User", "StreamOwn"));
         PostOverview model = new PostOverview();
         model.SubMenu = controller;
         User user  = this.UserDB.GetByUserName(User.Identity.Name);
         var  Posts = this.PostDB.All()
                      .Where(post => post.Author.Id == user.Id ||
                             post.Author.Followers.Contains(user) ||
                             post.Tags
                             .Where(tag => tag.Followers.Contains(user))
                             .FirstOrDefault() != null)
                      .Distinct();
         if (null == search)
         {
             model.Posts.AddRange(Posts
                                  .OrderByDescending(post => post.TimeOfPost)
                                  .Select(post => new PostLight(post)));
         }
         else // Add filtering
         {
             model.Posts.AddRange(Posts
                                  .Where(post => "title" == type && post.Title.ToLower().Contains(search.ToLower()) ||
                                         "user" == type && post.Author.Username.ToLower().Contains(search.ToLower()) ||
                                         "text" == type && post.Text.ToLower().Contains(search.ToLower()))
                                  .OrderByDescending(post => post.TimeOfPost)
                                  .Select(post => new PostLight(post)));
         }
         return(View(model));
     }
 }
Ejemplo n.º 4
0
        //
        // GET: /Post/ByTag/5
        public ActionResult ByTag(int id, string type, string search = null)
        {
            var tag   = this.TagDB.Find(id);
            var posts = from post in this.PostDB.All()
                        where post.Tags.Contains(tag) &&
                        (null == search ||
                         "title" == type && post.Title.ToLower().Contains(search.ToLower()) ||
                         "user" == type && post.Author.Username.ToLower().Contains(search.ToLower()) ||
                         "text" == type && post.Text.ToLower().Contains(search.ToLower()))
                        orderby post.TimeOfPost descending
                        select post;
            PostOverview model = new PostOverview();

            model.Key = new IDLight(tag.Id, tag.Text);
            model.Posts.AddRange(posts.Select(post => new PostLight(post)));
            User user = this.UserDB.GetByUserName(User.Identity.Name);

            ViewBag.IsFollower = (bool)(this.TagDB.All()
                                        .Where(t => t.Id == id)
                                        .Where(t => t.Followers.Contains(user))
                                        .SingleOrDefault() != null);
            return(View(model));
        }
Ejemplo n.º 5
0
        //
        // GET: /Post/ByAuthor/5
        public ActionResult ByAuthor(int id, string type, string search = null)
        {
            var author = RepositoryFactory.GetUserRepository().Find(id);
            var posts  = from post in this.PostDB.All()
                         where post.Author.Id == id &&
                         (search == null ||
                          "title" == type && post.Title.ToLower().Contains(search.ToLower()) ||
                          "user" == type && post.Author.Username.ToLower().Contains(search.ToLower()) ||
                          "text" == type && post.Text.ToLower().Contains(search.ToLower()))
                         orderby post.TimeOfPost descending
                         select post;
            PostOverview model = new PostOverview();

            model.Key = new IDLight(author.Id, author.Username);
            model.Posts.AddRange(posts.Select(post => new PostLight(post)));
            User user = this.UserDB.GetByUserName(User.Identity.Name);

            ViewBag.IsFollower = (bool)(this.UserDB.All()
                                        .Where(u => u.Id == id)
                                        .Where(u => u.Followers.Contains(user))
                                        .SingleOrDefault() != null);
            ViewBag.IsMyself = (bool)(user.Id == id);
            return(View(model));
        }