Beispiel #1
0
 public int GeneratePostSlugs(string ticket)
 {
     using (DBlog.Data.Hibernate.Session.OpenConnection(GetNewConnection()))
     {
         ISession session = DBlog.Data.Hibernate.Session.Current;
         CheckAdministrator(session, ticket);
         IList<Post> list = session.CreateCriteria(typeof(Post))
             .Add(Restrictions.IsNull("Slug"))
             .List<Post>();
         foreach(Post post in list)
         {
             TransitPost t_post = new TransitPost(session, post, true);
             t_post.GenerateSlug(session);
             post.Slug = t_post.Slug;
             session.Save(post);
             session.Flush();
         }
         return list.Count;
     }
 }
Beispiel #2
0
        public int CreateOrUpdatePost(string ticket, TransitPost t_post)
        {
            using (DBlog.Data.Hibernate.Session.OpenConnection(GetNewConnection()))
            {
                ISession session = DBlog.Data.Hibernate.Session.Current;
                CheckAdministrator(session, ticket);
                if (t_post.LoginId == 0) t_post.LoginId = ManagedLogin.GetLoginId(ticket);
                t_post.GenerateSlug(session);
                Post post = t_post.GetPost(session);
                post.Modified = DateTime.UtcNow;
                if (post.Id == 0) post.Created = post.Modified;
                session.SaveOrUpdate(post);

                if (t_post.Topics != null)
                {
                    foreach (TransitTopic t_topic in t_post.Topics)
                    {
                        if (t_topic.Id == 0)
                        {
                            Topic topic = t_topic.GetTopic(session);
                            session.SaveOrUpdate(topic);
                            t_topic.Id = topic.Id;
                        }
                    }
                }

                List<PostTopic> postTopicsToBeCreated = null;
                List<PostTopic> postTopicsToBeDeleted = null;
                TransitTopic.MergeTo(session, post, t_post.Topics, out postTopicsToBeCreated, out postTopicsToBeDeleted);
                foreach (PostTopic postTopic in postTopicsToBeCreated) session.Save(postTopic);
                foreach (PostTopic postTopic in postTopicsToBeDeleted) session.Delete(postTopic);
                session.Flush();
                return post.Id;
            }
        }