Example #1
0
        public void Modify(Document aDocument)
        {
            aDocument.LastModifyDate = DateTime.Today;

            IBodyDataAccess bodyDataAccess = new BodyDataAccess();

            foreach (Body body in aDocument.DocumentMargins)
            {
                bodyDataAccess.Add(body);
            }

            IParagraphDataAccess paragraphDataAccess = new ParagraphDataAccess();

            foreach (Paragraph paragraph in aDocument.DocumentParagraphs)
            {
                paragraphDataAccess.Add(paragraph);
            }

            using (DocSystDbContext context = new DocSystDbContext())
            {
                IList <Margin>    bodyList      = AttachDocumentMarginList(context, aDocument.DocumentMargins);
                IList <Paragraph> paragraphList = AttachDocumentParagraphsList(context, aDocument.DocumentParagraphs);
                aDocument.DocumentMargins    = bodyList.ToList();
                aDocument.DocumentParagraphs = paragraphList.ToList();

                Document actualDocument = context.Documents.Include("DocumentMargins").Include("DocumentParagraphs")
                                          .FirstOrDefault(documenthDb => documenthDb.Id == aDocument.Id);

                context.Entry(actualDocument).Entity.DocumentMargins    = aDocument.DocumentMargins;
                context.Entry(actualDocument).Entity.DocumentParagraphs = aDocument.DocumentParagraphs;
                context.Entry(actualDocument).CurrentValues.SetValues(aDocument);

                context.SaveChanges();
            }
        }
Example #2
0
        public void Add(Document aDocument)
        {
            IBodyDataAccess bodyDataAccess = new BodyDataAccess();

            foreach (Body body in aDocument.DocumentMargins)
            {
                bodyDataAccess.Add(body);
            }

            IParagraphDataAccess paragraphDataAccess = new ParagraphDataAccess();

            foreach (Paragraph paragraph in aDocument.DocumentParagraphs)
            {
                paragraphDataAccess.Add(paragraph);
            }

            using (DocSystDbContext context = new DocSystDbContext())
            {
                aDocument.CreatorUser        = AttachCreatorUser(context, aDocument.CreatorUser);
                aDocument.DocumentMargins    = AttachDocumentMarginList(context, aDocument.DocumentMargins).ToList();
                aDocument.DocumentParagraphs = AttachDocumentParagraphsList(context, aDocument.DocumentParagraphs).ToList();
                context.Documents.Add(aDocument);
                context.SaveChanges();
            }
        }