Exemplo n.º 1
0
        private static int SaveArticleMetaInfo(ArticleMetaInfo info)
        {
            var articleId = info.Id;

            using (SqlConnection connection = new SqlConnection(DatabaseConnector.getDbConnectionStringBuilder().ConnectionString))
            {
                connection.Open();
                var sql = $"Content.SaveArticle";
                using (SqlCommand command = new SqlCommand(sql, connection))
                {
                    command.CommandType = CommandType.StoredProcedure;
                    command.Parameters.Add("@Id", SqlDbType.Int).Value                   = info.Id;
                    command.Parameters.Add("@Subject", SqlDbType.NVarChar).Value         = info.Subject;
                    command.Parameters.Add("@Author", SqlDbType.NVarChar).Value          = info.Author;
                    command.Parameters.Add("@CategoryName", SqlDbType.NVarChar).Value    = info.Category;
                    command.Parameters.Add("@SubCategoryName", SqlDbType.NVarChar).Value = info.SubCategory;
                    command.Parameters.Add("@Level", SqlDbType.Int).Value                = info.Level;
                    command.Parameters.Add("@NewArticleId", SqlDbType.Int).Direction     = ParameterDirection.ReturnValue;
                    command.ExecuteNonQuery();
                    articleId = (int)command.Parameters["@NewArticleId"].Value;
                }
            }

            return(articleId);
        }
Exemplo n.º 2
0
        public static ArticleMetaInfo GetArticleMetaInfo(int articleId)
        {
            using (SqlConnection connection = new SqlConnection(DatabaseConnector.getDbConnectionStringBuilder().ConnectionString))
            {
                connection.Open();
                var sql = $@"SELECT a.Id, a.[Subject], a.Author, c.[Name] AS Category, sc.[Name] AS SubCategory, a.[Level], a.Created 
                            FROM Content.Articles a
                                INNER JOIN Content.Categories c ON c.Id = a.CategoryId
                                INNER JOIN Content.SubCategories sc ON sc.Id = a.SubCategoryId
                            WHERE a.Id = {articleId}";

                using (SqlCommand command = new SqlCommand(sql, connection))
                {
                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        reader.Read();
                        return(ArticleMetaInfo.LoadFromReader(reader));
                    }
                }
            }
        }