/// <summary> /// 获取文章详细内容 /// </summary> /// <param name="aid">文章详细模型</param> public ArticleDetailsModel GetOneArticleContentByID(Guid aid) { IRepository <Article> rep = Factory.Factory <IRepository <Article> > .GetConcrete <Article>(); IRepository <BlogComment> commentRep = Factory.Factory <IRepository <BlogComment> > .GetConcrete <BlogComment>(); Article article = null; ArticleDetailsModel target = null; IList <CommentDspModel> comments = null; try { article = rep.GetByKey(aid); if (article != null) { IList <BlogComment> list = commentRep.FindAll(new Specification <BlogComment>(c => c.TargetId == aid).OrderBy(c => c.CreationDate).Skip(0).Take(10000)); if (list != null) { comments = new List <CommentDspModel>(); foreach (BlogComment c in list) { CommentDspModel tmp = new CommentDspModel() { AccountID = c.AccountInfo.Id, TargetID = c.TargetId, UserName = c.AccountInfo.UserName, CommentContent = c.Body, CreatedOn = c.CreationDate, CommentID = c.Id }; comments.Add(tmp); } } target = new ArticleDetailsModel() { Body = article.ArticleVO.Body, Title = article.ArticleVO.Title, CategoryID = article.CategoryID, CategoryName = article.CategoryName, ClickCount = article.ArticleVO.ClickCount, CommentCount = article.ArticleVO.CommentCount, CreationDate = article.CreationDate, SourceSite = article.ArticleVO.SourceSite, SourceUrl = article.ArticleVO.SourceUrl, UserID = article.UserID, BriefTitle = article.ArticleVO.BriefTitle, UserName = article.UserName, Comments = comments }; } else { return(target); } } catch (Exception error) { throw new Exception(error.Message); } return(target); }
public ArticleDetailsModel GetArticle(int id) { var artMod = new ArticleDetailsModel(); var article = _articleRepository.AsQueryable().Include(x => x.Comments).ThenInclude(y => y.Author) .FirstOrDefault(x => x.Id == id); return(_mapper.Map <ArticleDetailsModel>(article)); }
public void ArticleDetailsModel_ShouldShowGradeAverageWithTwoDecimals() { var article = new Article(); article.Author = new User { UserName = "******" }; article.Body = ""; var model = new ArticleDetailsModel(article, "asmunde"); Assert.That(model.GradeAverage, Is.EqualTo("3.00")); }
public void UpdateArticle(ArticleDetailsModel model) { var article = this._db.NewsArticles.Find(model.Id); article.Id = model.Id; article.AuthorId = model.AuthorId; article.Content = model.Content; article.PublishDate = DateTime.UtcNow; article.Title = model.Title; this._db.NewsArticles.Update(article); this._db.SaveChanges(); }
public ActionResult Details(string id) { Article article = _articleSrv.GetByCode(id); if (article != null) { ArticleDetailsModel model = _mapper.Map <ArticleDetailsModel>(article); return(View(model)); } else { _log.Error("[Details] Brak artykulu o code = '{0}'", id); return(RedirectToAction("List")); } }
protected override void OnPreRender(EventArgs e) { Lable_id.Text = Request["id"].ToString(); if (Lable_id.Text != null) { ArticleDetailsModel model = cmssservice.GetOneArticleContentByID(new Guid(Lable_id.Text)); ArticleTitle.Text = model.Title; editorcontent.Value = model.Body; BindCategory(model.CategoryID); ArticleWeb.Text = model.SourceSite; ArticleLink.Text = model.SourceUrl; ArticleBriefTitle.Text = model.BriefTitle; } base.OnPreRender(e); }
public void ArticleDetailsModel_ShouldShowGradeGivenByCurrentUser() { var article = new Article(); article.Author = new User { UserName = "******" }; article.Grades.Add(new Grade { User = article.Author, GradeValue = 4 }); article.Body = ""; var model = new ArticleDetailsModel(article, "asmunde"); Assert.That(model.GradeValue, Is.EqualTo(4)); }
public async Task <ActionResult> DetailsAsync(int id) { var articles = await _blogDbContext.Articles.FindAsync(id); ArticleDetailsModel model = new ArticleDetailsModel { Id = articles.Id, Title = articles.Title, ImagePath = articles.ImagePath, Description = articles.Description, ShortDescription = articles.ShortDescription, Author = new AuthorModel { UserId = articles.Author.UserId, Description = articles.Author.Description, ProFilePicture = articles.Author.ProfilePicture, Name = articles.Author.Name, Surname = articles.Author.Surname }, Tags = articles.Tags.Select(t => new TagModel { Id = t.Id, Name = t.Name }).ToList(), Comments = articles.Comments.Select(c => new CommentModel { Id = c.Id, CommentDate = c.CommentDate, Text = c.Text, Email = c.Email, WebSite = c.WebSite, Article = c.Article, ArticleId = c.ArticleId, Name = c.Name, UserImage = c.UserImage }).ToList() }; if (articles == null) { return(RedirectToAction("Error", "Home")); } return(View(model)); }
public IActionResult UpdateArticle(int id, ArticleDetailsModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (model != null) { this._newsArticles.UpdateArticle(model); TempData.AddSuccessMessage($"Successfully edited Article"); return(RedirectToAction(nameof(AdminListing))); } TempData.ErrorMessage($"Article does not exist"); return(RedirectToAction(nameof(CustomersController.Index), new { area = "Admin" })); }
public async Task <ActionResult> Details(int id) { //Search for Article by Id var article = await _blogDbContext.Articles.FindAsync(id); if (article == null) { return(RedirectToAction("Error", "Home")); } ArticleDetailsModel model = new ArticleDetailsModel { Author = new AuthorModel { AuthorName = article.Author.AuthorName, AuthorSurname = article.Author.AuthorSurname, Description = article.Author.Description, UserId = article.Author.UserId }, Description = article.Description, Id = article.Id, ImagePath = article.ImagePath, ShortDescription = article.ShortDescription, Title = article.Title, Tags = article.Tags.Select(c => new TagModel { Id = c.Id, Name = c.Name }).ToList(), Comments = article.Comments.Select(c => new CommentModel { ArticleId = c.ArticleId, Email = c.Email, Name = c.Name, Text = c.Text, WebSite = c.WebSite, Id = c.Id, CommentDate = c.CommentDate }).ToList() }; return(View(model)); }
public async Task <IActionResult> Details(Guid id) { Post post = await this.postService.GetPostByIdAsync(id); if (post == null || post.PostStatus != PostStatus.Publish || post.PostType != PostType.Article) { return(NotFound()); } else { await this.postService.IncreaseViewNumAsync(post); PersonView person = await this.personService.GetPersonViewAsync(post.PersonId); ArticleDetailsModel model = new ArticleDetailsModel { Post = post, Person = person }; return(View(model)); } }