Пример #1
0
        public void AddArticle(Article _article, string[] categories, string[] tags)
        {
            Add(_article);

            if (categories != null)
            {
                foreach (var item in categories)
                {
                    int categoryID             = Convert.ToInt32(item);
                    Article_Category _category = new Article_Category();
                    _category.CategoryID = categoryID;
                    _category.ArticleID  = _article.ID;
                    Database.ArticleCategories.Add(_category);
                    Save();
                }
            }
            if (tags != null)
            {
                foreach (var item in tags)
                {
                    int         tagID = Convert.ToInt32(item);
                    Article_Tag _tag  = new Article_Tag();
                    _tag.TagID     = tagID;
                    _tag.ArticleID = _article.ID;
                    Database.ArticleTags.Add(_tag);
                    Save();
                }
            }
        }
Пример #2
0
        public void EditArticle(Article _article, string[] categories, string[] tags)
        {
            Edit(_article);
            foreach (var tag in Database.ArticleTags.ToList())
            {
                if (tag.ArticleID == _article.ID)
                {
                    Database.ArticleTags.Remove(tag);
                    Save();
                }
            }

            foreach (var category in Database.ArticleCategories.ToList())
            {
                if (category.ArticleID == _article.ID)
                {
                    Database.ArticleCategories.Remove(category);
                    Save();
                }
            }
            if (categories != null)
            {
                foreach (var item in categories)
                {
                    int categoryID             = Convert.ToInt32(item);
                    Article_Category _category = new Article_Category();
                    _category.CategoryID = categoryID;
                    _category.ArticleID  = _article.ID;
                    Database.ArticleCategories.Add(_category);
                    Save();
                }
            }
            if (tags != null)
            {
                foreach (var item in tags)
                {
                    int         tagID = Convert.ToInt32(item);
                    Article_Tag _tag  = new Article_Tag();
                    _tag.TagID     = tagID;
                    _tag.ArticleID = _article.ID;
                    Database.ArticleTags.Add(_tag);
                    Save();
                }
            }
        }