/// <summary> /// 收藏帖子 /// </summary> public ReturnResult <bool> AddArticleCollect(ArticleCollectDataContract articleCollect, int categoryId) { int rootCategoryId = articleCategoryService.GetRootCategoryId(categoryId); if (rootCategoryId == -1) { return(new ReturnResult <bool>(101, false, "分类参数错误")); } articleCollect.TableName = "SA_ArticleContent" + rootCategoryId; if (ArticleCollectRepository.Instance.IsExists(articleCollect.ArticleID, articleCollect.TableName)) { return(new ReturnResult <bool>(true)); } var article = ArticleContentRepository.Instance.GetArticle(rootCategoryId, articleCollect.ArticleID); if (null == article) { return(new ReturnResult <bool>(102, false, "未找到指定的帖子")); } articleCollect.Title = article.Title; articleCollect.Author = article.Author; articleCollect.AuthorUserKeyId = article.UserKeyId; articleCollect.CollectTime = DateTime.Now; if (ArticleCollectRepository.Instance.InsertArticleCollect(articleCollect)) { System.Threading.Tasks.Task.Factory.StartNew(() => articleContentService.UpdateArticleCount(article.ArticleID, article.CategoryId, articleCollect.UserKeyId, ArticleCountEnum.CollectCount)); return(new ReturnResult <bool>(true)); } return(new ReturnResult <bool>(103, false, "收藏失败")); }
public JsonResult CollectArticle(OauthToken token, long articleId, int categoryId) { var model = new ArticleCollectDataContract() { UserKeyId = token.UserKeyId, ArticleID = articleId, CollectTime = DateTime.Now }; return(Json(articleCollectService.AddArticleCollect(model, categoryId), JsonRequestBehavior.AllowGet)); }
public bool InsertArticleCollect(ArticleCollectDataContract articleCollect) { string sql = @"INSERT INTO SA_ArticleCollect(ArticleID,TableName,UserKeyId,Title,Author,AuthorUserKeyId,CollectTime) VALUES(@ArticleID,@TableName,@UserKeyId,@Title,@Author,@AuthorUserKeyId,@CollectTime);SELECT @@IDENTITY;" ; var _parm = new SqlParameter[] { new SqlParameter("@ArticleID", articleCollect.ArticleID), new SqlParameter("@TableName", articleCollect.TableName), new SqlParameter("@UserKeyId", articleCollect.UserKeyId), new SqlParameter("@Title", articleCollect.Title), new SqlParameter("@Author", articleCollect.Author), new SqlParameter("@AuthorUserKeyId", articleCollect.AuthorUserKeyId), new SqlParameter("@CollectTime", articleCollect.CollectTime) }; articleCollect.CollectId = Convert.ToInt32(SqlHelper.ExecuteScalar(SqlHelper.GetConnSting(), CommandType.Text, sql, _parm)); return(articleCollect.CollectId > 0); }