public static IEnumerable <Post> GetPosts(int postsPerPage = 0) { var posts = from p in PostManager.GetAllPosts() where ((p.Status == PostStatus.Published && p.PubDate <= DateTime.Now) || HttpContext.Current.User.Identity.IsAuthenticated) && (p.Type == PostType.Post) select p; string category = HttpContext.Current.Request.QueryString["category"]; if (!string.IsNullOrEmpty(category)) { posts = posts.Where(p => p.Categories.Any(c => string.Equals(c, category, StringComparison.OrdinalIgnoreCase))); } string tag = HttpContext.Current.Request.QueryString["tag"]; if (!string.IsNullOrEmpty(tag)) { posts = posts.Where(p => p.Tags.Any(c => string.Equals(c, tag, StringComparison.OrdinalIgnoreCase))); } string author = HttpContext.Current.Request.QueryString["author"]; if (!string.IsNullOrEmpty(author)) { posts = posts.Where(p => p.Author.ToLower() == author); } if (postsPerPage > 0) { posts = posts.Skip(postsPerPage * (CurrentPage - 1)).Take(postsPerPage); } return(posts); }
public JsonResult ListNewestFourPosts() { PostManager manager = new PostManager(); var result = manager.GetAllPosts().Where(a => a.StatusID == 2).OrderByDescending(a => a.PostID).Take(4).ToList(); return(Json(result, JsonRequestBehavior.AllowGet)); }
private void EditPost(string Slug, string title, string excerpt, string content, DateTime pubDate, bool isPublished, string[] categories) { Post post; post = PostManager.GetAllPosts().FirstOrDefault(p => p.Slug == Slug); if (post != null) { post.Title = title; post.Description = excerpt; post.Content = content; post.PubDate = pubDate; post.Categories = categories.ToList(); //post.IsPublished = isPublished; } else { post = new Post() { Title = title, Description = excerpt, Content = content, PubDate = pubDate, Slug = CreateSlug(title), Categories = categories.ToList() }; HttpContext.Current.Response.Write(post.Url); } SaveFilesToDisk(post); //post.IsPublished = isPublished; //PostManager.Save(post); }
public ActionResult AdminPageByStatus(int id) { PostManager manager = new PostManager(); var posts = manager.GetAllPosts().Where(a => a.StatusID == id); return(View(posts)); }
public ActionResult ViewPostAsAdmin(int id) { PostManager manager = new PostManager(); var post = manager.GetAllPosts().FirstOrDefault(a => a.PostID == id); post.Comments = CommentManager.GetComment(id); return(View(post)); }
public ActionResult ManageCurrentPosts() { var repo = new PostManager(); var model = repo.GetAllPosts(); return(View(model)); }
public ActionResult SubmitForApprovalPost(int id) { PostManager manager = new PostManager(); var post = manager.GetAllPosts().FirstOrDefault(a => a.PostID == id); post.StatusID = 1; manager.SubmitForApprovalPost(post); return(View("PostStatusUpdateSuccess", post)); }
public ActionResult NeedRevisionsPost(int id) { PostManager manager = new PostManager(); var post = manager.GetAllPosts().FirstOrDefault(a => a.PostID == id); post.StatusID = 5; manager.NeedsRevisionsPost(post); return(View("PostStatusUpdateSuccess", post)); }
public static string CreateSlug(string title) { title = title.ToLowerInvariant().Replace(" ", "-").Replace("#", ""); title = RemoveDiacritics(title); if (PostManager.GetAllPosts().Any(p => string.Equals(p.Slug, title, StringComparison.OrdinalIgnoreCase))) { throw new HttpException(409, "Already in use"); } return(title.ToLowerInvariant()); }
public static List <string> GetTags() { var tags = PostManager.GetAllPosts() .Where(p => ((p.Status == PostStatus.Published && p.PubDate <= DateTime.UtcNow) || HttpContext.Current.User.Identity.IsAuthenticated)) .SelectMany(x => x.Tags).ToList().Distinct(); var list = tags.ToList(); list.Sort(); return(list); }
public ActionResult GetPostsWithCategory(int id) { PostManager manager = new PostManager(); var allPosts = manager.GetAllPosts(); var catPosts = new List <Post>(); foreach (var post in allPosts) { if (post.CategoryID == id) { catPosts.Add(post); } } return(View(catPosts)); }
public ActionResult ViewAllPosts() { var viewModel = new PostVM(); //viewModel.SetCategoryItems(_categoryManager.GetAllCategories()); viewModel.SetTagItems(_tagManager.GetAllTags()); viewModel.Categories = _categoryManager.GetAllCategories(); viewModel.Posts = _postManager.GetAllPosts(); foreach (var c in viewModel.Categories) { c.NumberOfPosts = viewModel.Posts.Where(a => a.CategoryID == c.CategoryID).Select(a => a).Where(a => a.StatusID == 2).Count(); } //viewModel.NumberOfPosts = _postManager.NumberOfPostsPerCategory(viewModel.Post.CategoryID); return(View(viewModel)); }
public static Dictionary <string, int> GetCategories() { var categoryStrings = PostManager.GetAllPosts() .Where(p => ((p.Status == PostStatus.Published && p.PubDate <= DateTime.UtcNow) || HttpContext.Current.User.Identity.IsAuthenticated)) .SelectMany(x => x.Categories).ToList().Distinct(); var result = new Dictionary <string, int>(); foreach (var cat in categoryStrings) { result.Add(cat, PostManager.GetAllPosts() .Where(p => ((p.Status == PostStatus.Published && p.PubDate <= DateTime.UtcNow) || HttpContext.Current.User.Identity.IsAuthenticated)) .Count(p => p.Categories.Any(c => string.Equals(c, cat, StringComparison.OrdinalIgnoreCase))) ); } return(result); }
//public ActionResult ListCategories() //{ // var categories = _categoryManager.GetAllCategories(); // var posts = _postManager.GetAllPosts(); // foreach (var c in categories) // { // c.NumberOfPosts = _categoryManager.NumberOfPostsPerCategory(c); // } // return View("_ViewCategories"); //} public ActionResult GetPostsWithTag(int id) { PostManager manager = new PostManager(); var allPosts = manager.GetAllPosts(); var taggedPosts = new List <Post>(); foreach (var post in allPosts) { foreach (var tag in post.PostTags) { if (tag.TagID == id) { taggedPosts.Add(post); } } } return(View(taggedPosts)); }
public async void GetAllPosts_GetsExpectedPostObjects() { DbContextOptions <TwaddleDbContext> options = new DbContextOptionsBuilder <TwaddleDbContext>().UseInMemoryDatabase("GetPostObjects").Options; using (TwaddleDbContext _context = new TwaddleDbContext(options)) { //arrange Post one = new Post(); Post two = new Post(); Post three = new Post(); Post four = new Post(); Post five = new Post(); one.Caption = "one"; two.Caption = "two"; three.Caption = "three"; four.Caption = "four"; five.Caption = "five"; await _context.Posts.AddAsync(one); await _context.Posts.AddAsync(two); await _context.Posts.AddAsync(three); await _context.Posts.AddAsync(four); await _context.Posts.AddAsync(five); await _context.SaveChangesAsync(); //act PostManager service = new PostManager(_context); var query = await service.GetAllPosts(); List <Post> queryList = query.ToList <Post>(); //assert Assert.Equal("five", queryList[4].Caption); } }
public async void GetAllPosts_GetsAllPosts() { DbContextOptions <TwaddleDbContext> options = new DbContextOptionsBuilder <TwaddleDbContext>().UseInMemoryDatabase("GetAllPosts").Options; using (TwaddleDbContext _context = new TwaddleDbContext(options)) { //arrange Post one = new Post(); Post two = new Post(); Post three = new Post(); Post four = new Post(); Post five = new Post(); await _context.Posts.AddAsync(one); await _context.Posts.AddAsync(two); await _context.Posts.AddAsync(three); await _context.Posts.AddAsync(four); await _context.Posts.AddAsync(five); await _context.SaveChangesAsync(); //act PostManager service = new PostManager(_context); var query = await service.GetAllPosts(); int count = query.ToList <Post>().Count; //assert Assert.Equal(5, count); } }
public ActionResult ViewIndividualPost(int?id) { PostManager manager = new PostManager(); try { var post = manager.GetAllPosts().FirstOrDefault(a => a.PostID == id); if (post == null) { return(View("Error404")); } if (post.StatusID != 2) { return(View("Error404")); } return(View(post)); } catch { return(View("Error404")); } }
public string GetAllPosts() { return(JsonConvert.SerializeObject(PostManager.GetAllPosts())); }
public ActionResult EditPosts() { var posts = _postManager.GetAllPosts(); return(View(posts)); }
public Post[] GetAllPosts() { return(PostManager.GetAllPosts()); }