public void CreateSection()
        {
            var section = new DalSection()
            {
                CreationDate = DateTime.Now,
                IsBlocked    = false,
                SectionName  = "Stars",
                UserRefId    = 1
            };

            SectionRepository.Create(section);
            Context.SaveChanges();
        }
        public static Section cloneSectionFromTemplate(SectionTemplate t, Document d)
        {
            using (ISession session = NHibernateHelper.OpenSession())
            {
                IAuditReader reader = AuditReaderFactory.Get(session);
                var revision = reader.CreateQuery()
                                .ForRevisionsOfEntity(typeof(SectionTemplate), false, true)
                                .AddProjection(AuditEntity.RevisionNumber().Max())
                                .Add(AuditEntity.Id().Eq(t.id))
                                .GetSingleResult();

                Section s = new Section();
                s.template = t;
                s.templateRevisionId = (int)revision;
                s.documentIndex = t.documentIndex;
                s.headline = t.headline;
                s.htmlContent = t.htmlContent;
                s.document = d;

                SectionRepository repo = new SectionRepository();

                repo.Create(s);

                foreach (DataFieldTemplate item in t.dataFields)
                {
                    DataField df = cloneDataFieldFromTemplate(item, s);

                    string toReplace = "{dataField=" + item.id + "}";
                    string replaceWith = "{dataField=" + df.id + "}";

                    s.htmlContent = s.htmlContent.Replace(toReplace, replaceWith);
                }

                repo.Update(s);

                return s;
            }
        }