예제 #1
0
        public ActionResult FilterPosts()
        {
            SuperPosts SP = new SuperPosts();

            SP.AllTags = db.Tags.ToList();
            List <Post> P = db.Posts.ToList();

            SP.Posts = P;
            return(View(SP));
        }
예제 #2
0
        public ActionResult FilterPosts(string filter)
        {
            SuperPosts SP = new SuperPosts();

            SP.AllTags = db.Tags.ToList();
            List <Post> P = db.Posts.ToList();

            SP.Posts = new List <Post>();

            if (filter != "" && filter != null)
            {
                filter = filter.Substring(0, filter.Length - 1);
                List <string> arr = filter.Split(',').ToList();
                for (int i = 0; i < arr.Count; i++)
                {
                    SP.SearchTags.Add(db.Tags.Find(Int32.Parse(arr[i])));
                }
                foreach (var p in P)
                {
                    for (int i = 0; i < arr.Count; i++)
                    {
                        int id      = Int32.Parse(arr[i]);
                        var posttag = db.PostTags.Where(x => x.Post.IdPost == p.IdPost && x.Tag.TagId == id).FirstOrDefault();
                        if (posttag != null)
                        {
                            SP.Posts.Add(p);
                            Tag tag = db.Tags.Where(x => x.TagId == posttag.Tag.TagId).FirstOrDefault();
                            SP.SearchTags.Add(tag);
                        }
                    }
                }
            }
            else
            {
                SP.Posts = P;
            }
            return(View(SP));
        }