Example #1
0
        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;
            }
        }
Example #2
0
        public static void init()
        {
            //Init company
            //Company c = new Company();
            //c.name = "Lauge IT ApS";
            //new CompanyRepository().Create(c);

            ////Init document
            //Document d = new Document();
            //d.ownerCompany = c;
            //d.title = "Ansættelsesaftale - Klaus";
            //new DocumentRepository().Create(d);

            ////Init sections
            //Section s1 = new Section { headline = "Indledning", htmlContent = "Aftalen indgåes mellem[br /]{dataField=1}[br /](herefter kaldet virksomheden)[br /]og[br /]{dataField=2}[br /](herefter kaldet medarbejderen)", documentIndex = 1, document = d };
            //Section s2 = new Section { headline = "Medarbejderens oplysninger", htmlContent = "Medarbejderens stilling: {dataField=3}[br /]", documentIndex = 2, document = d };

            //SectionRepository sr = new SectionRepository();

            //sr.Create(s1);
            //sr.Create(s2);

            ////Init datafields
            //DataField d1 = new DataField { description = "Virksomheden", value = "Lauge IT ApS", section = s1 };
            //DataField d2 = new DataField { description = "Medarbejderen", value = "Kenneth Lauge Madsen", section = s1 };
            //DataField d3 = new DataField { description = "Medarbejderens stilling", value = "IT-Chef", section = s2 };

            //DataFieldRepository dr = new DataFieldRepository();

            //dr.Create(d1);
            //dr.Create(d2);
            //dr.Create(d3);

            //Init category
            ProductCategory pcBlank = new ProductCategory { name = "Brugerdefineret" };
            ProductCategory pc = new ProductCategory { name = "Ansættelsesaftale" };

            new ProductCategoryRepository().Create(pcBlank);
            new ProductCategoryRepository().Create(pc);

            //Init template
            DocumentTemplate dtBlank = new DocumentTemplate { name = "Blankt dokument", productCategory = pcBlank };
            DocumentTemplate dt = new DocumentTemplate { name = "Funktionærkontrakt", description = "Funktionær kontrakter bruges ved ansatte der ikke er timelønnede", productCategory = pc };

            SectionTemplate st1 = new SectionTemplate { headline = "Indledning", documentIndex = 1, document = dt };
            SectionTemplate st2 = new SectionTemplate { headline = "Medarbejderens oplysninger", documentIndex = 2, document = dt };

            DataFieldTemplate dt1 = new DataFieldTemplate { description = "Virksomheden", section = st1 };
            DataFieldTemplate dt2 = new DataFieldTemplate { description = "Medarbejderen", section = st1 };
            DataFieldTemplate dt3 = new DataFieldTemplate { description = "Medarbejderens stilling", section = st2 };

            new DocumentTemplateRepository().Create(dtBlank);
            new DocumentTemplateRepository().Create(dt);

            SectionTemplateRepository str = new SectionTemplateRepository();

            str.Create(st1);
            str.Create(st2);

            DataFieldTemplateRepository dtr = new DataFieldTemplateRepository();

            dtr.Create(dt1);
            dtr.Create(dt2);
            dtr.Create(dt3);

            st1.htmlContent = "Aftalen indgåes mellem<br />{{" + dt1.description + "}}<br />(herefter kaldet virksomheden)<br />og<br />{{" + dt2.description + "}}<br />(herefter kaldet medarbejderen)";
            st2.htmlContent = "Medarbejderens stilling: {{" + dt3.description + "}}<br />";

            str.Update(st1);
            str.Update(st2);

            //Create user
            //User u1 = new User { firstName = "Kenneth" };
            //UserEmail e1 = new UserEmail { email = "*****@*****.**", user = u1 };
            //User u2 = new User { firstName = "Erik" };
            //UserEmail e2 = new UserEmail { email = "*****@*****.**", user = u2 };

            //UserRepository ur = new UserRepository();
            //UserEmailRepository uer = new UserEmailRepository();

            //ur.Create(u1);
            //ur.Create(u2);
            //uer.Create(e1);
            //uer.Create(e2);
        }