protected virtual ArticlePostListModels PrepareArticlePostListModel(ArticlePagingFilteringModel command) { if (command == null) { throw new ArgumentNullException("command"); } var model = new ArticlePostListModels(); if (command.PageSize <= 0) { command.PageSize = 15; } if (command.PageNumber <= 0) { command.PageNumber = 1; } IPagedList <ArticlePost> articlePosts; articlePosts = _articlePostService.GetPagedList(command.PageIndex, command.PageSize); model.PagingFilteringContext.LoadPagedList(articlePosts); model.ArticlePosts = articlePosts.Select(x => { var articlePostModels = new ArticlePostModels(); PrepareArticlePostModel(articlePostModels, x, false); return(articlePostModels); }).ToList(); return(model); }
protected virtual void PrepareArticlePostModel(ArticlePostModels model, ArticlePost articlePost, bool prepareComments) { if (articlePost == null) { throw new ArgumentNullException("articlePost"); } if (model == null) { throw new ArgumentNullException("model"); } model.Id = articlePost.Id; model.Title = articlePost.Title; model.Body = articlePost.Body; model.MetaDescription = articlePost.MetaDescription; model.CreatedOnUtc = articlePost.CreatedOnUtc; model.MetaKeywords = articlePost.MetaKeywords; model.MetaTitle = articlePost.MetaTitle; model.Tags = articlePost.Tags; if (prepareComments) { var articleComments = articlePost.ArticleComments.OrderBy(pr => pr.CreatedOnUtc); foreach (var ac in articleComments) { var commentModel = new ArticleCommentModels { Id = ac.Id, MemberId = ac.MemberId, MemberName = ac.Member.UName, CommentText = ac.CommentText, CreatedOnUtc = ac.CreatedOnUtc }; model.Comments.Add(commentModel); } } }
public ActionResult Show(int id) { ArticlePost ap = _articlePostService.GetById(id); if (ap == null) { return(Redirect("Index")); } var model = new ArticlePostModels(); PrepareArticlePostModel(model, ap, true); ViewBag.Title = model.Title; ViewBag.Keywords = model.MetaKeywords; ViewBag.Description = model.MetaDescription; return(View(model)); }
public JsonResult SetPostContent(ArticlePostModels article) { var status = EJState.Failed; if (article != null) { if (article.PostType != null) { var post = _articleService.GetPost(article.PostType.Value); if (post != null) { post.Title = article.Title; post.Content = article.Content; _articleService.UpdatePost(post); } else { Post newPost = new Post { Title = article.Title, Content = article.Content, PostType = article.PostType.Value, CreatedBy = User.Identity.Name, CreatedTimestamp = DateTime.UtcNow }; _articleService.InsertPost(newPost); } if (_articleService.SaveChange(User.Identity.GetUserId <int>())) { status = EJState.Success; } } } return(Json(new { status = status }, JsonRequestBehavior.AllowGet)); }
public ActionResult Add(ArticlePostModels model) { if (ModelState.IsValid) { try { var m = new ArticlePost() { Title = model.Title, Body = model.Body, AllowComments = true, CreatedOnUtc = DateTime.Now, MetaDescription = model.MetaDescription, MetaKeywords = model.MetaKeywords, MetaTitle = model.MetaTitle, CommentCount = 0, Intro = model.Intro, Tags = model.Tags }; _articlePostService.Add(m); if (m.Id > 0) { return(View("Add", model)); } } catch (Exception ex) { logger.Error(ex); } //return RedirectToAction("Index", "Home"); } // If we got this far, something failed, redisplay form return(View(model)); }