public SingleModel GetById(int id) { Article article = articleRepository.Find(id); SingleModel model = mapper.Map <SingleModel>(article); return(model); }
//public void Appraise(int articleId, AppraiseModel model) //{ // Article article = articleRepository.Find(articleId); // article.Appraise = new Appraise // { // IsAgree = model.IsAgree, // Voter = GetCurrentUser() // }; // article.Agree(article.Appraise.Voter); // articleRepository.Save(article); //} public void Edit(int id, EditModel model) { Article article = articleRepository.Find(id); mapper.Map <EditModel, Article>(model, article); articleRepository.Edit(); }
public void OnGet() { //int id = Convert.ToInt32(Request.Query["Id"]); int id = Convert.ToInt32(RouteData.Values["id"]); Article = articleRepository.Find(id); PreviousPage = articleRepository.Find(id - 1); NextPage = articleRepository.Find(id + 1); }
public void OnGet() { // int id = Convert.ToInt32(Request.Query["id"][0]); int id = Convert.ToInt32(RouteData.Values["id"]); PreID = id - 1; NextID = id + 1; Article = ArticleRepository.Find(id); PreTitle = ArticleRepository.Find(PreID).Title; NextTitle = ArticleRepository.Find(NextID).Title; ViewData["AgreeCount"] = 3; }
public void OnGet() { int id = Convert.ToInt32(RouteData.Values["id"]); //int id = Convert.ToInt32(Request.Query["id"][0]); Article = articleRepository.Find(id); ViewData["AgreeCount"] = 3; }
public void OnGet() { //int id = int.Parse(Request.Query["id"][0]); //int id = int.Parse((string)RouteData.Values["id"]); int id = Convert.ToInt32(RouteData.Values["id"]); Article = articleRepository.Find(id); }
public ActionResult Detail(int id = 0) { var model = repository.Find(id); if (model == null) { return(View("Index")); } return(View("Write", model)); }
/// <summary> ///发布一篇评论和能够回复别人评论 /// </summary> /// <param name="model"></param> /// <param name="articleId"></param> /// <returns></returns> public CommentModel Save(CommentModel model) { Comment comment = mapper.Map <Comment>(model); comment.Publish(); comment.Author = GetCurrentUser(); comment.Reply = commentRepository.Find(model.CommentId); //当前被评论的Id comment.Article = articleRepository.Find(model.ArticleSingleModel.Id); //评论文章的Id CommentModel commentModel = GetById(commentRepository.Save(comment)); return(commentModel); }
/// <summary> /// 文章的点赞和点踩 /// </summary> /// <param name="id"></param> /// <param name="direction"></param> /// <returns></returns> public int SaveArticle(int id, string direction) { Appraise appraise = new Appraise(); appraise.Voter = GetCurrentUser(); appraise.Article = articleRepository.Find(id); if (direction == "1") { appraise.UpCount += 1; } else { appraise.DownCount += 1; } return(appraiseRepository.Save(appraise)); }
} //Model里面有一个Entity对象 public void OnGet() { Article = articleRepository.Find(8); //通过Repository拿到Entity对象 }