public DocumentContentModel(Document document)
        {
            this.Id = document.Id;
            this.Title = document.Title;
            this.Description = document.Description;

            if (document.DocumentSections != null)
            {
                this.Sections = document.DocumentSections.ToList()
                                                         .ConvertAll(item => new DocumentSectionModel().FromEntity(item));
            }
        }
Пример #2
0
        public Document Add(Document document)
        {
            try
            {
                document.CreatedBy = _context.Contributors.Find(_contributorId);
                document.CreatedOn = DateTime.Now;
                document.Project = _context.Projects.Find(document.Project.Id);

                document = _context.Documents.Add(document);
                _context.SaveChanges();
            }
            catch (DbEntityValidationException ex)
            {
                DebuggerTool.Write(ex);
            }
            return document;
        }
Пример #3
0
        public Document Update(Document document)
        {
            try
            {
                Document documentToUpdate = _context.Documents.Include(item => item.CreatedBy)
                                                                          .Where(item => item.Id == document.Id)
                                                                          .FirstOrDefault();

                documentToUpdate.Title = document.Title;
                documentToUpdate.Description = document.Description;
                documentToUpdate.Project = _context.Projects.Find(document.Project.Id);

                _context.SaveChanges();
            }
            catch (DbEntityValidationException ex)
            {
                DebuggerTool.Write(ex);
            }

            return document;
        }