internal Post GetPostsById(int id) { Post post = _repo.GetById(id); if (post == null) { throw new Exception("Invalid Id"); } return(post); }
public IActionResult ViewPost(int id) { var repos = new PostsRepository(_connectionString); var post = repos.GetById(id); return(View(post)); }
public ActionResult Edit(int id) { PostsRepository repo = new PostsRepository(); Post item = repo.GetById(id); EditVM model = new EditVM(item); model.SubRedditsList = new List <SelectListItem>(); SubRedditsRepository subRedditsRepo = new SubRedditsRepository(); List <SubReddit> subscribedSubReddits = subRedditsRepo.GetMySubscribes(AuthManager.LoggedUser.Id).ToList(); foreach (SubReddit subReddit in subscribedSubReddits) { if (!(AuthManager.LoggedUser.BannedInSubReddits.Any(sr => sr.BannedUsers.Any(u => u.Id == AuthManager.LoggedUser.Id)) || AuthManager.LoggedUser.MutedInSubReddits.Any(sr => sr.MutedUsers.Any(u => u.Id == AuthManager.LoggedUser.Id)))) { model.SubRedditsList.Add( new SelectListItem() { Value = subReddit.Id.ToString(), Text = subReddit.Name, Selected = subReddit.Id == model.SelectedSubReddit }); } } //model.SubRedditId = model.SelectedSubReddit; return(PartialView("~/Views/Partials/Edits/_EditPost.cshtml", model)); }
public IActionResult GetLikes(int id) { var repo = new PostsRepository(_connectionString); var post = repo.GetById(id); post.Likes = repo.GetLikesCount(id); return(Json(post)); }
public ActionResult Approve(int id) { PostsRepository repo = new PostsRepository(); Post post = repo.GetById(id); repo.ApprovePost(id, AuthManager.LoggedUser.Id); return(RedirectToAction("Index", "Posts", new { SubRedditId = post.SubRedditId })); }
public ActionResult Delete(int id) { PostsRepository repo = new PostsRepository(); Post item = repo.GetById(id); repo.Delete(item); return(RedirectToAction("Index", "Posts", new { SubRedditId = item.SubRedditId })); }
public void should_retrieve_post_by_id(int id) { // Arrange var mockPosts = PostsHelper.GetDefaultMockData(); var db = new InMemoryDatabase(); db.Insert <Post>(mockPosts); _connectionFactory.GetConnection().Returns(db.OpenConnection()); var mockPost = mockPosts.Where(x => x.Id == id).FirstOrDefault(); // Act var post = _sut.GetById(id); // Assert Assert.IsNotNull(post); Assert.IsTrue(mockPost.Id == post.Id); Assert.IsTrue(mockPost.Title == post.Title); Assert.IsTrue(mockPost.Text == post.Text); }
public ActionResult Details(int id) { var post = PostsRepository.GetById(id, p => new DetailsModel { Id = p.Id, Title = p.Title, Description = p.Description, ImageUrls = p.ImageUrls, CreatedAt = p.Edited ? p.CreatedAt : (DateTime?)null, Edited = p.Edited, EditedAt = p.Edited ? p.UpdatedAt : (DateTime?)null }); return(Ok(post)); }
public IActionResult AddLikes(int id) { var repo = new PostsRepository(_connectionString); List <int> likes = HttpContext.Session.Get <List <int> >("Likes"); if (likes == null) { likes = new List <int>(); } else if (likes.Contains(id)) { return(null); } likes.Add(id); HttpContext.Session.Set("Likes", likes); var post = repo.GetById(id); repo.AddLike(id); return(Json(post)); }
// GET: Comments public ActionResult Index(IndexVM model, int?PostId) { if (PostId != null) { model.PostId = (int)PostId; } CommentsRepository repo = new CommentsRepository(); model.Items = repo.GetAll(m => m.PostId == model.PostId); PostsRepository postsRepo = new PostsRepository(); model.Post = postsRepo.GetById(model.PostId); UsersRepository usersRepo = new UsersRepository(); model.User = usersRepo.GetById(model.UserId); return(View(model)); }
public Post Get(int id) { Post post = _repo.GetById(id); return(post); }