protected override void ReverseDocumentUpdate(ContactMaint graph, Contact entity)
        {
            // need for right update Documents
            //Base.Caches<Contact>().SetStatus(entity, PXEntryStatus.Inserted);

            var doc = Documents.Current;

            Documents.Cache.SetValue <Document.refContactID>(doc, entity.ContactID);
            graph.Caches <TMain>().Update(GetMain(doc));

            var contact = Contacts.Current ?? Contacts.SelectSingle();

            Contacts.Cache.SetValue <DocumentContact.firstName>(contact, entity.FirstName);
            Contacts.Cache.SetValue <DocumentContact.lastName>(contact, entity.LastName);
            Contacts.Cache.SetValue <DocumentContact.salutation>(contact, entity.Salutation);
            Contacts.Cache.SetValue <DocumentContact.phone1>(contact, entity.Phone1);
            Contacts.Cache.SetValue <DocumentContact.phone1Type>(contact, entity.Phone1Type);
            Contacts.Cache.SetValue <DocumentContact.email>(contact, entity.EMail);
            var contactMain = Contacts.Cache.GetMain(contact);

            graph.Caches[contactMain.GetType()].Update(contactMain);
        }
        protected override Contact CreateMaster(ContactMaint graph, ContactConversionOptions _)
        {
            var entity           = Documents.Current;
            var param            = ContactInfo.Current;
            var docContact       = Contacts.Current ?? Contacts.SelectSingle();
            var docContactMethod = ContactMethod.Current ?? ContactMethod.SelectSingle();
            var docAddress       = Addresses.Current ?? Addresses.SelectSingle();

            Contact contact = new Contact
            {
                ContactType      = ContactTypesAttribute.Person,
                ParentBAccountID = entity.ParentBAccountID
            };

            MapContact(docContact, contact);
            MapConsentable(docContact, contact);

            contact.FirstName        = param.FirstName;
            contact.LastName         = param.LastName;
            contact.Salutation       = param.Salutation;
            contact.Phone1           = param.Phone1;
            contact.Phone1Type       = param.Phone1Type;
            contact.EMail            = param.Email;
            contact.ContactType      = ContactTypesAttribute.Person;
            contact.ParentBAccountID = entity.ParentBAccountID;
            contact.BAccountID       = entity.BAccountID;
            contact.Source           = entity.Source;

            MapContactMethod(docContactMethod, contact);

            var address = (Address)graph.AddressCurrent.Cache.CreateInstance();

            address = graph.AddressCurrent.Insert(address);

            contact = graph.Contact.Insert(contact);

            contact.ClassID = param.ContactClass;

            CRContactClass cls = PXSelect <
                CRContactClass,
                Where <
                    CRContactClass.classID, Equal <Required <CRContactClass.classID> > > >
                                 .SelectSingleBound(graph, null, contact.ClassID);

            if (cls?.DefaultOwner == CRDefaultOwnerAttribute.Source)
            {
                contact.WorkgroupID = entity.WorkgroupID;
                contact.OwnerID     = entity.OwnerID;
            }

            MapAddress(docAddress, address);

            address = (Address)graph.AddressCurrent.Cache.Update(address);

            contact.DefAddressID = address.AddressID;

            contact = graph.Contact.Update(contact);

            ReverseDocumentUpdate(graph, contact);

            FillRelations(graph.Relations, contact);

            FillAttributes(graph.Answers, contact);

            TransferActivities(graph, contact);

            // Copy Note text and Files references
            CRSetup setup = PXSetupOptional <CRSetup> .Select(graph);

            PXNoteAttribute.CopyNoteAndFiles(graph.Caches <TMain>(), Documents.Cache.GetMain(entity), graph.Contact.Cache, contact, setup);

            return(graph.Contact.Update(contact));
        }