示例#1
0
        public void SaveArticle(Article article)
        {
            using (var dbContext = new CmsDbContext())
            {
                var tags = new List<Tag>();

                foreach (var tag in article.Tags)
                {
                    var existTag = dbContext.Tags.FirstOrDefault(t => t.Name == tag.Name);
                    if (existTag != null)
                        existTag.Hits++;
                    tags.Add(existTag ?? tag);
                }

                if (article.ID > 0)
                {
                    article.TagString = string.Empty;
                    dbContext.Update<Article>(article);
                    dbContext.Entry(article).Collection(m => m.Tags).Load();
                    article.Tags = tags;
                    dbContext.SaveChanges();
                }
                else
                {
                    article.Tags = tags;
                    dbContext.Insert<Article>(article);
                }
            }
        }
示例#2
0
 public void SaveChannel(Channel channel)
 {
     using (var dbContext = new CmsDbContext())
     {
         if (channel.ID > 0)
         {
             dbContext.Update<Channel>(channel);
         }
         else
         {
             dbContext.Insert<Channel>(channel);
         }
     }
 }