Exemplo n.º 1
0
        public static bool UpsertYxArticle(YouXuanArticle article, string user)
        {
            var result    = false;
            var articleId = 0;

            try
            {
                var conn = ConfigurationManager.ConnectionStrings["Tuhu_Discovery_Db"].ConnectionString;
                if (SecurityHelp.IsBase64Formatted(conn))
                {
                    conn = SecurityHelp.DecryptAES(conn);
                }
                using (var dbhelper = new SqlDbHelper(conn))
                {
                    dbhelper.BeginTransaction();
                    if (article.PKID > 0)
                    {
                        articleId = article.PKID;
                        ArticleDal.UpdateYxArticle(dbhelper, article);
                    }
                    else
                    {
                        articleId = ArticleDal.InsertYxArticle(dbhelper, article);
                    }
                    article.CoverConfig.ArticleId = articleId;
                    ArticleDal.DeleteYxArticleCoverConfig(dbhelper, articleId);
                    ArticleDal.DeleteArticleCategoryTag(dbhelper, articleId);
                    if (!string.IsNullOrEmpty(article.CategoryTags))
                    {
                        var categoryIds = JsonConvert.DeserializeObject <List <JObject> >(article.CategoryTags).Select(t => t.Value <int>("key"));
                        foreach (var id in categoryIds)
                        {
                            ArticleDal.InsertArticleCategoryTag(dbhelper, articleId, id);
                        }
                    }
                    ArticleDal.InsertYxArticleCoverConfig(dbhelper, article.CoverConfig);
                    dbhelper.Commit();
                    result = true;
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex);
            }
            if (result)
            {
                if (article.PKID > 0)
                {
                    LoggerManager.InsertOplog(user, "ArticleTblNew", articleId, "新增优选文章,文章状态:" + article.Status);
                }
                else
                {
                    LoggerManager.InsertOplog(user, "ArticleTblNew", articleId, "修改优选文章,文章状态:" + article.Status);
                }
            }
            return(result);
        }