Example #1
0
        public static Document cloneDocumentFromTemplate(DocumentTemplate t)
        {
            using (ISession session = NHibernateHelper.OpenSession())
            {
                IAuditReader reader = AuditReaderFactory.Get(session);
                var revision = reader.CreateQuery()
                                .ForRevisionsOfEntity(typeof(DocumentTemplate), false, true)
                                .AddProjection(AuditEntity.RevisionNumber().Max())
                                .Add(AuditEntity.Id().Eq(t.id))
                                .GetSingleResult();

                Document d = new Document();
                d.template = t;
                d.templateRevisionId = (int)revision;

                new DocumentRepository().Create(d);

                foreach (SectionTemplate item in t.sections)
                {
                    Section s = cloneSectionFromTemplate(item, d);
                }

                return d;
            }
        }
Example #2
0
        public static int getCurrentRevision(Document document)
        {
            if (document.id != null)
            {
                using (ISession session = NHibernateHelper.OpenSession())
                {
                    IAuditReader reader = AuditReaderFactory.Get(session);
                    var revision = reader.CreateQuery()
                                    .ForRevisionsOfEntity(typeof(Document), false, true)
                                    .AddProjection(AuditEntity.RevisionNumber().Max())
                                    .Add(AuditEntity.Id().Eq(document.id))
                                    .GetSingleResult();

                    return (int)revision;
                }
            }
            else
            {
                return 0;
            }
        }
Example #3
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 #4
0
        public static string GetPrint(Document document)
        {
            //Check if sections != null
            if (document.sections==null)
            {
                throw new Exception("Document sections cannot be null");
            }

            string html;

            //Start of file
            html = "<html><head><title>" + document.title + "</title></head><body>" + System.Environment.NewLine + "<h1>" + document.title + "</h1>" + System.Environment.NewLine;

            foreach (Section s in document.sections.OrderBy(o => o.documentIndex))
            {
                html = html + "<h2>" + s.documentIndex + ". " + s.headline + "</h2>" + System.Environment.NewLine;
                html = html + s.renderHtml() + System.Environment.NewLine;
            }

            //End of file
            html = html + "</body></html>";

            return html;
        }
Example #5
0
        public virtual bool Equals(Document d)
        {
            // If parameter is null return false.
            if (d == null)
            {
                return false;
            }

            //Check id
            if (!(d.id == null && id == null))
            {
                if (d.id == null || id == null)
                {
                    return false;
                }

                if (d.id != id)
                {
                    return false;
                }
            }

            //Check title
            if (!(d.title == null && title == null))
            {
                if (d.title == null || title == null)
                {
                    return false;
                }

                if (!d.title.Equals(title))
                {
                    return false;
                }
            }

            //Check variables
            if (d.templateRevisionId != templateRevisionId || d.lockedForSign != lockedForSign)
            {
                return false;
            }

            //Check datetimes - creation
            if (!(d.creation == null && creation == null))
            {
                if (d.creation == null || creation == null)
                {
                    return false;
                }

                if (!d.creation.Equals(creation))
                {
                    return false;
                }
            }

            //Check datetimes - expiration
            if (!(d.expiration == null && expiration == null))
            {
                if (d.expiration == null || expiration == null)
                {
                    return false;
                }

                if (!d.expiration.Equals(expiration))
                {
                    return false;
                }
            }

            //Check object members - ownerCompany
            if (!(d.ownerCompany == null && ownerCompany == null))
            {
                if (d.ownerCompany == null || ownerCompany == null)
                {
                    return false;
                }

                if (d.ownerCompany.id != ownerCompany.id)
                {
                    return false;
                }
            }
            //Check object members - ownerUser
            if (!(d.ownerUser == null && ownerUser == null))
            {
                if (d.ownerUser == null || ownerUser == null)
                {
                    return false;
                }

                if (d.ownerUser.id != ownerUser.id)
                {
                    return false;
                }
            }
            //Check object members - template
            if (!(d.template == null && template == null))
            {
                if (d.template == null || template == null)
                {
                    return false;
                }

                if (d.template.id != template.id)
                {
                    return false;
                }
            }

            //Check collections - section
            if (!(d.sections == null && sections == null))
            {
                if (d.sections == null || sections == null)
                {
                    return false;
                }

                return Enumerable.SequenceEqual(d.sections.OrderBy(x => x.documentIndex), sections.OrderBy(x => x.documentIndex));
            }

            return true;
        }
 public ActionResult RedigerTitel(Document document)
 {
     try
     {
         if (ModelState.IsValid)
         {
             var response = HttpClientFactory.getClient(this.ControllerContext).PutAsJsonAsync("document/update/" + document.id, document).Result;
             if (response.IsSuccessStatusCode)
             {
                 return Json(new { validModelstate = true });
             }
             else
             {
                 return Json(new { validModelstate = false, statusCode = response.StatusCode });
             }
         }
         else
         {
             return PartialView(document);
         }
     }
     catch (Exception e)
     {
         throw new Exception("Could not update!", e);
     }
 }
        public HttpResponseMessage Update(int id, Document item)
        {
            if (ModelState.IsValid)
            {
                item.id = id;
                try
                {
                    repo.Update(item);
                    var response = Request.CreateResponse<Document>(HttpStatusCode.OK, item);

                    return response;
                }
                catch (Exception)
                {
                    throw new HttpResponseException(HttpStatusCode.NotFound);
                }
            }
            else
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }
        }