Beispiel #1
0
        public List <ArticleCategoryViewModel> Categories()
        {
            List <ArticleCategoryViewModel> l = new List <ArticleCategoryViewModel>();

            using (SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString)) {
                using (SqlCommand cmd = new SqlCommand("SELECT ArticleCategorySerial, CategoryName, SortOrder FROM cms_ArticleCategory WHERE ModuleID = @ModuleID AND Locale = @Locale ORDER BY SortOrder, CategoryName", cn)) {
                    cmd.CommandType = CommandType.Text;
                    cmd.Parameters.Add("ModuleID", SqlDbType.UniqueIdentifier).Value = _ModuleID;
                    cmd.Parameters.Add("Locale", SqlDbType.VarChar, 10).Value        = _Locale;
                    cmd.Connection.Open();
                    SqlDataReader dr = cmd.ExecuteReader();
                    while (dr.Read())
                    {
                        ArticleCategoryViewModel cat = new ArticleCategoryViewModel();
                        cat.ArticleCategorySerial = dr.GetInt32(0);
                        cat.ModuleID     = _ModuleID;
                        cat.CategoryName = dr.GetString(1);
                        cat.SortOrder    = dr.GetInt32(2);
                        l.Add(cat);
                    }
                    cmd.Connection.Close();
                }
            }
            return(l);
        }
Beispiel #2
0
        public void Add(ArticleCategoryViewModel articleViewModel)
        {
            using (SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString)) {
                using (SqlCommand cmd = new SqlCommand("INSERT INTO cms_ArticleCategory (ModuleID, Locale, CategoryName, SortOrder) VALUES (@ModuleID, @Locale, @CategoryName, @SortOrder)", cn)) {
                    cmd.CommandType = CommandType.Text;
                    cmd.Parameters.Add("ModuleID", SqlDbType.UniqueIdentifier).Value = _ModuleID;
                    cmd.Parameters.Add("Locale", SqlDbType.VarChar, 10).Value        = _Locale;
                    cmd.Parameters.Add("CategoryName", SqlDbType.NVarChar).Value     = articleViewModel.CategoryName;
                    cmd.Parameters.Add("SortOrder", SqlDbType.Int).Value             = articleViewModel.SortOrder;

                    cmd.Connection.Open();
                    cmd.ExecuteNonQuery();
                    cmd.Connection.Close();
                }
            }
        }