public PersonalDocument Update(PersonalDocument entity)
        {
            var xmlEntity = Utility.ConvertPersonalDocumentEntityToXml(entity);
            Utility.ValidateXmlEntity(xmlEntity);

            string secretPhrase = GetSecretPhrase();
            var e = new MyXDocument(entity, secretPhrase);

            using (var db = new PersonalIdContext())
            {
                var dbEntity = db.Documents.Single(a => a.Id == entity.Id);
                dbEntity = e;
                db.SaveChanges();

                return entity;
            }
        }
        public PersonalDocument Add(PersonalDocument entity)
        {
            string secretPhrase = GetSecretPhrase();
            var e = new MyXDocument(entity, secretPhrase);

            //write it to file
            //Utility.WriteEntityToXmlFile(entity);

            using (var db = new PersonalIdContext())
            {
                db.Documents.Add(e);
                db.SaveChanges();

                entity.Id = e.Id;
                return entity;
            }
        }
        public void Delete(PersonalDocument entity)
        {
            string secretPhrase = GetSecretPhrase();
            var xEntity = new MyXDocument(entity, secretPhrase);

            using (var db = new PersonalIdContext())
            {
                var entry = db.Entry(xEntity);
                if (entry.State != EntityState.Deleted)
                {
                    entry.State = EntityState.Deleted;
                }
                else
                {
                    db.Set<MyXDocument>().Attach(xEntity);
                    db.Set<MyXDocument>().Remove(xEntity);
                }
                db.SaveChanges();
            }

        }