Inheritance: IEntity
 public static int Add(Article article)
 {
     if (article.ParentObjectID > 0)
     {
         Article article2 = GetArticle(article.ParentObjectID, article.LanguageID);
         if (article2 != null)
             throw new Exception("Article is exists in the same language, please choose another language");
     }
     return ArticleDataMapper.Add(article);
 }
        internal static void FillFromReader(Article article, SqlDataReader reader)
        {
            int colIndex = 0;
            colIndex = reader.GetOrdinal(CN_ARTICLE_CATEGORY_ID);
            if (!reader.IsDBNull(colIndex))
                article.CategoryID = reader.GetInt32(colIndex);

            int days = 0, seconds = 0;
            colIndex = reader.GetOrdinal(CN_ARTICLE_CREATION_DAY);
            if (!reader.IsDBNull(colIndex))
                days = reader.GetInt32(colIndex);

            colIndex = reader.GetOrdinal(CN_ARTICLE_CREATION_SEC);
            if (!reader.IsDBNull(colIndex))
                seconds = reader.GetInt32(colIndex);

            article.CreationDate = CMSCoreHelper.GetDateTime(days, seconds);

            colIndex = reader.GetOrdinal(CN_ARTICLE_DESCRIPTION);
            if (!reader.IsDBNull(colIndex))
                article.Description = reader.GetString(colIndex);

            colIndex = reader.GetOrdinal(CN_ARTICLE_DETAILS);
            if (!reader.IsDBNull(colIndex))
                article.Details = reader.GetString(colIndex);

            colIndex = reader.GetOrdinal(CN_ARTICLE_ID);
            if (!reader.IsDBNull(colIndex))
                article.ID = reader.GetInt32(colIndex);

            colIndex = reader.GetOrdinal(CN_ARTICLE_IMAGE);
            if (!reader.IsDBNull(colIndex))
                article.Image = reader.GetString(colIndex);

            colIndex = reader.GetOrdinal(CN_ARTICLE_IS_DELETED);
            if (!reader.IsDBNull(colIndex))
                article.IsDeleted = reader.GetBoolean(colIndex);

            colIndex = reader.GetOrdinal(CN_ARTICLE_KEYWORDS);
            if (!reader.IsDBNull(colIndex))
                article.KeyWords = reader.GetString(colIndex);

            colIndex = reader.GetOrdinal(CN_ARTICLE_LANGUAGE_ID);
            if (!reader.IsDBNull(colIndex))
                article.LanguageID = reader.GetInt32(colIndex);

            colIndex = reader.GetOrdinal(CN_ARTICLE_NAME);
            if (!reader.IsDBNull(colIndex))
                article.Name = reader.GetString(colIndex);

            colIndex = reader.GetOrdinal(CN_ARTICLE_SUMMARY);
            if (!reader.IsDBNull(colIndex))
                article.Summary = reader.GetString(colIndex);

            colIndex = reader.GetOrdinal(CN_ARTICLE_PORTAL_ID);
            if (!reader.IsDBNull(colIndex))
                article.PortalID = reader.GetInt32(colIndex);

            colIndex = reader.GetOrdinal(CN_ARTICLE_SEO_NAME);
            if (!reader.IsDBNull(colIndex))
                article.SEOName = reader.GetString(colIndex);

            colIndex = reader.GetOrdinal(CN_ARTICLE_URL);
            if (!reader.IsDBNull(colIndex))
                article.URL = reader.GetString(colIndex);

            colIndex = reader.GetOrdinal(CN_ARTICLE_TYPE);
            if (!reader.IsDBNull(colIndex))
                article.ArticleType = (CMSEnums.ArticleType)reader.GetInt32(colIndex);

            colIndex = reader.GetOrdinal(CN_ARTICLE_ORDER);
            if (!reader.IsDBNull(colIndex))
                article.Order = reader.GetInt32(colIndex);

            colIndex = reader.GetOrdinal(CN_ARTICLE_CREATED_BY);
            if (!reader.IsDBNull(colIndex))
                article.CreatedBy = reader.GetInt32(colIndex);

            colIndex = reader.GetOrdinal(CN_ARTICLE_PARENT_OBJ_ID);
            if (!reader.IsDBNull(colIndex))
                article.ParentObjectID = reader.GetInt32(colIndex);

            colIndex = reader.GetOrdinal(CN_ARTICLE_VIEW_COUNT);
            if (!reader.IsDBNull(colIndex))
                article.ViewCount = reader.GetInt32(colIndex);

            colIndex = reader.GetOrdinal(PublishDataMapper.CN_PUBLISH_TYPE_ID);
            if (!reader.IsDBNull(colIndex))
                article.IsPublished = reader.GetInt32(colIndex) == (int)CMSEnums.PublishType.PublishNow;
        }
        internal static Article GetArticle(List<Article> articles, SqlDataReader reader)
        {
            int colIndex = 0;
            colIndex = reader.GetOrdinal(CN_ARTICLE_ID);
            int value = reader.GetInt32(colIndex);

            Article article = articles.Where(c => c.ID == value).FirstOrDefault();
            if (article == null)
            {
                article = new Article();
                articles.Add(article);
            }
            return article;
        }
        internal static Article GetArticle(int articleParentObjID, int languageID)
        {
            Article article = null;

            using (SqlConnection sqlConnection = new SqlConnection(CMSCoreBase.CMSCoreConnectionString))
            {
                SqlCommand sqlCommand = new SqlCommand(SN_ARTICLE_GET_BY_PARENT_OBJ_ID, sqlConnection);
                sqlCommand.CommandType = System.Data.CommandType.StoredProcedure;

                SqlParameter sqlParameter = null;

                sqlParameter = new SqlParameter(PN_ARTICLE_PARENT_OBJ_ID, System.Data.SqlDbType.Int);
                sqlParameter.Direction = System.Data.ParameterDirection.Input;
                sqlParameter.Value = articleParentObjID;
                sqlCommand.Parameters.Add(sqlParameter);

                sqlParameter = new SqlParameter(PN_ARTICLE_LANGUAGE_ID, System.Data.SqlDbType.Int);
                sqlParameter.Direction = System.Data.ParameterDirection.Input;
                sqlParameter.Value = languageID;
                sqlCommand.Parameters.Add(sqlParameter);

                sqlParameter = new SqlParameter(PublishDataMapper.PN_PUBLISH_MODULE_ID, System.Data.SqlDbType.Int);
                sqlParameter.Direction = System.Data.ParameterDirection.Input;
                sqlParameter.Value = (int)CMSEnums.Modules.Article;
                sqlCommand.Parameters.Add(sqlParameter);

                sqlCommand.Connection.Open();
                using (SqlDataReader sqlDataReader = sqlCommand.ExecuteReader(System.Data.CommandBehavior.CloseConnection))
                {
                    while (sqlDataReader.Read())
                    {
                        if (article == null)
                            article = new Article();
                        FillFromReader(article, sqlDataReader);
                    }
                    sqlDataReader.Close();
                    sqlCommand.Connection.Close();
                }
            }
            return article;
        }
 public static void Update(Article article)
 {
     ArticleDataMapper.Update(article);
 }