Example #1
0
        public void SaveDocuments()
        {
            foreach (var documentViewModel in Documents)
            {
                documentViewModel.PersonId = _id;
            }

            var documents = Documents.AcceptChanges();

            using (var session = _documentStoreFactory.CreateDocumentStore().OpenSession())
            {
                foreach (var documentViewModel in documents)
                {
                    var document = documentViewModel.AcceptChanges();
                    session.Store(document);
                    documentViewModel.Id = document.Id;
                }

                var documentsToDelete = session.Query <Document>().Where(t => t.PersonId == _id).ToList().Where(t => documents.Any(d => d.Id == t.Id) == false);
                foreach (var document in documentsToDelete)
                {
                    session.Delete(document.Id);
                }

                session.SaveChanges();
            }
        }