Beispiel #1
0
        public PartialViewResult LastOnesFromFolloweds()
        {
            PostRepo pr      = new PostRepo();
            Random   rnd     = new Random();
            User     current = Session["user"] as User;

            List <Post> posts      = pr.GetFollowedPosts(current.UserID, 2);
            List <Post> shortPosts = new List <Post>();

            if (posts.Count > 12)
            {
                for (int i = 0; i < 12;)
                {
                    Post p = posts[rnd.Next(0, posts.Count)];
                    if (!shortPosts.Contains(p))
                    {
                        shortPosts.Add(p);
                        i++;
                    }
                }
            }
            else
            {
                shortPosts = posts;
            }

            return(PartialView("~/Views/Shared/_PostShowcasePartial.cshtml", shortPosts));
        }
Beispiel #2
0
        public void CanFindPreviousPublishedPost(int postid, int x)
        {
            PostRepo repo = new PostRepo();
            int      prev = repo.FindPreviousPublishedPost(postid);

            Assert.AreEqual(x, prev);
        }
        public ActionResult EditPost(int id)
        {
            PostRepo reap  = new PostRepo();
            var      model = reap.GetPostById(id);

            return(View(model));
        }
Beispiel #4
0
        public void CanloadCommentsbyID(int postID, int x)
        {
            PostRepo       repo = new PostRepo();
            List <Comment> cmts = repo.GetCommentsbyPost(postID);

            Assert.AreEqual(x, cmts.Count());
        }
Beispiel #5
0
        public void CanLoadCategoriesbyPost(int postID, int x)
        {
            PostRepo        repo = new PostRepo();
            List <Category> cats = repo.GetCategoryByPost(postID);

            Assert.AreEqual(x, cats.Count());
        }
        public IActionResult GetAllPosts()
        {
            var items = PostRepo.GetAllPosts();

            items = RefreshAuthorMaps(items);
            return(new OkObjectResult(items));
        }
Beispiel #7
0
        public async Task <ActionResult <Post> > Upload([FromBody] UploadArgument upload)
        {
            User user = Request.GetUser();

            if (user == null)
            {
                return(Unauthorized());
            }
            List <byte[]> images = await upload.ParseImages();

            string contents = upload.contents.Trim();
            Post   post;

            if (upload.groupAuthor == null)
            {
                post = await PostRepo.Add(contents, user, images, upload.location);
            }
            else
            {
                int groupAuthor = (int)upload.groupAuthor;
                if (await GroupRepo.IsMember(groupAuthor, user))
                {
                    post = await PostRepo.AddGroupAuthor(contents, groupAuthor, images, upload.location);
                }
                else
                {
                    return(Unauthorized());
                }
            }
            return(Ok(post));
        }
Beispiel #8
0
        public void GetPosts()
        {
            PostRepo    repo  = new PostRepo();
            List <Post> posts = repo.GetAllPosts().ToList();

            Assert.AreEqual(9, posts.Count());
        }
Beispiel #9
0
        public void CanFindFirstPublishedpost()
        {
            PostRepo repo  = new PostRepo();
            int      first = repo.FindFirstPublishedPost();

            Assert.AreEqual(1, first);
        }
Beispiel #10
0
        // GET: Home
        public ActionResult Index()
        {
            postRepo = new PostRepo(database);
            IEnumerable <Post> posts = postRepo.GetPublicPosts();

            return(View(new HomeViewModel(posts)));
        }
Beispiel #11
0
        public void CanGetUnapprovedReplies()
        {
            PostRepo     repo = new PostRepo();
            List <Reply> reps = repo.GetUnapprovedReplies();

            Assert.AreEqual(1, reps.Count);
        }
Beispiel #12
0
        public void CanGetPostForreview()
        {
            PostRepo    repo  = new PostRepo();
            List <Post> posts = repo.GetPostForReview();

            Assert.AreEqual(1, posts.Count);
        }
Beispiel #13
0
        public void CanGetAuthors()
        {
            PostRepo      repo    = new PostRepo();
            List <string> authors = repo.GetAllAuthors();

            Assert.AreEqual(4, authors.Count);
        }
Beispiel #14
0
        public void CanGetStaticPublishedPosts()
        {
            PostRepo    repo  = new PostRepo();
            List <Post> posts = repo.GetAllStaticPublished();

            Assert.AreEqual(1, posts.Count());
        }
Beispiel #15
0
        public void CanFindLastPub()
        {
            PostRepo repo = new PostRepo();
            int      last = repo.FindLastPublishedPost();

            Assert.AreEqual(4, last);
        }
Beispiel #16
0
        public void CanGetPublishedPostByTitleSearch(string input, int x)
        {
            PostRepo    repo  = new PostRepo();
            List <Post> posts = repo.GetPublishedPostByTitle(input);

            Assert.AreEqual(x, posts.Count);
        }
        public ActionResult AddPost(int?id) //patametrenin null geldiğini gösterebilmek için ? koyuyoruz
        {
            if (id.HasValue)
            {
                ViewBag.Header = "Yazı Güncelle";
                var post = PostRepo.Get((int)id);
                var cat  = CatagoryRepo.Get(post.CategoryID);

                WPost vmpost = new WPost();
                vmpost.Title    = post.Title;
                vmpost.Content  = post.Concent;
                vmpost.Category = cat.Name;
                vmpost.PostID   = post.PostID;
                foreach (var item in post.Tags)
                {
                    vmpost.Tags += item.Name + ",";
                }

                return(View(vmpost));
            }
            else
            {
                ViewBag.Header = "Yazı Ekle";
                return(View());
            }
        }
Beispiel #18
0
        public void CanLoadCategories()
        {
            PostRepo        repo = new PostRepo();
            List <Category> cats = repo.GetAllCategories();

            Assert.AreEqual(3, cats.Count());
        }
Beispiel #19
0
    public IActionResult Create([FromForm] Post p)
    {
        PostRepo posts = new PostRepo();

        posts.Add(p);
        return(View());
    }
        public ActionResult ListPosts()
        {
            PostRepo reap  = new PostRepo();
            var      model = reap.GetAllPosts();

            return(View(model));
        }
        public ActionResult DeletePost(Post blog)
        {
            PostRepo reap = new PostRepo();

            reap.Delete(blog.Id);
            return(RedirectToAction("ListPosts"));
        }
Beispiel #22
0
        public void CanGetHashtagsbyID(int postid, int x)
        {
            PostRepo       repo = new PostRepo();
            List <HashTag> hts  = repo.GetHashtagbyPost(postid);

            Assert.AreEqual(x, hts.Count());
        }
Beispiel #23
0
        public void CanGetUnapprovedComments()
        {
            PostRepo       repo  = new PostRepo();
            List <Comment> comms = repo.GetUnapprovedComments();

            Assert.AreEqual(2, comms.Count);
        }
        public async Task <IActionResult> ShowPost(int year, string month, int day, string slug, int id = 0)
        {
            Post post;

            if (id > 0)
            {
                post = await PostRepo.GetPost(id);
            }
            else
            {
                post = await PostRepo.GetPost(slug);
            }

            // embed ads
            post.Body = post.Body.Replace("##AD##", ""); // no Ads at the moment exclusive

            //var body = StringUtils.ReplaceStringInstance(post.Body, "##AD##", App.EmbeddedContentAd, 2, true);
            //body = StringUtils.ReplaceStringInstance(body, "##AD##", App.WestWindSquareAd, 3, true);
            //body = body.Replace("##AD##", App.EmbeddedContentAd);

            var page = Request.Query["page"].FirstOrDefault();

            int.TryParse(page, out int pageToDisplay);
            if (pageToDisplay < 1)
            {
                pageToDisplay = 1;
            }

            List <string> pages = new List <string>();

            if (post.Body.Contains("#PAGEBREAK"))
            {
                pages = post.Body.Split(new[] { "#PAGEBREAK" }, StringSplitOptions.RemoveEmptyEntries).ToList();
            }
            if (pages.Count < 1)
            {
                pages.Add(post.Body);
            }

            var totalPages = pages.Count;

            if (totalPages == 0)
            {
                totalPages = 1;
            }

            if (pageToDisplay <= totalPages)
            {
                post.Body = pages[pageToDisplay - 1];
            }
            else
            {
                totalPages = 1;
            }

            return(View(new PostViewModel {
                Post = post, PostRepo = PostRepo, PageToDisplay = pageToDisplay, TotalPages = totalPages
            }));
        }
Beispiel #25
0
        public void GetPublishedPosts()
        {
            PostRepo    repo  = new PostRepo();
            List <Post> posts = repo.GetPublishedPosts();

            Assert.AreEqual(5, posts.Count());
            Assert.AreEqual("Hello Fellow Monster Hunters", posts[0].PostTitle);
        }
Beispiel #26
0
        public void GetPublishedRepliesByComment()
        {
            PostRepo     repo    = new PostRepo();
            List <Reply> replies = repo.GetPublishedReplies(1);

            Assert.AreEqual(1, replies.Count);
            Assert.AreEqual("I've seen better", replies[0].ReplyText);
        }
Beispiel #27
0
        public void CanFindNextPublished(int postid, int x)
        {
            PostRepo repo = new PostRepo();

            int next = repo.FindNextPublishedPost(postid);

            Assert.AreEqual(x, next);
        }
Beispiel #28
0
 protected void btnDelte_Click(object sender, EventArgs e)
 {
     if (int.TryParse(postId.Value, out int id))
     {
         PostRepo.DeletePost(id);
         Callback("Successfully Deleted", false);
     }
 }
Beispiel #29
0
        public void CanLoadHashtags()
        {
            PostRepo       repo = new PostRepo();
            List <HashTag> Cats = repo.GetHashtags();

            Assert.IsNotNull(Cats);
            Assert.AreEqual(8, Cats.Count());
        }
Beispiel #30
0
 public async Task <ActionResult <List <Post> > > GetGroupPosts(int id, int amount = 20, int offset = 0)
 {
     if ((await GroupRepo.Get(id)) == null)
     {
         return(NotFound());
     }
     return(Ok(await PostRepo.GetGroupFeedById(id, amount, offset)));
 }