Example #1
0
        public static void DeleteContacts(
            DataTable AContactLogs)
        {
            TDBTransaction Transaction  = new TDBTransaction();
            bool           SubmissionOK = false;

            DBAccess.WriteTransaction(
                ref Transaction,
                ref SubmissionOK,
                delegate
            {
                Boolean LastPartnerForThisContactLog = true;

                foreach (DataRow contactLogRow in AContactLogs.Rows)
                {
                    Int64 ContactLogId = Convert.ToInt64(contactLogRow["p_contact_log_id_i"]);
                    Int64 PartnerKey   = Convert.ToInt64(contactLogRow["p_partner_key_n"]);

                    LastPartnerForThisContactLog = true;

                    if (IsContactLogAssociatedWithMoreThanOnePartner(ContactLogId, Transaction))
                    {
                        LastPartnerForThisContactLog = false;
                    }

                    PPartnerContactTable contactLogs = PPartnerContactAccess.LoadByPrimaryKey(
                        PartnerKey, ContactLogId, Transaction);

                    contactLogs[0].Delete();

                    PPartnerContactAccess.SubmitChanges(contactLogs, Transaction);

                    if (LastPartnerForThisContactLog)
                    {
                        // now we also need to delete the contact attributes (linked with this contact log)
                        PPartnerContactAttributeRow template = new PPartnerContactAttributeTable().NewRowTyped(false);
                        template.ContactId = ContactLogId;

                        if (PPartnerContactAttributeAccess.CountUsingTemplate(template, null, Transaction) > 0)
                        {
                            PPartnerContactAttributeAccess.DeleteUsingTemplate(template, null, Transaction);
                        }

                        // and the contact log itself needs to be deleted (if no other partner refers to it)
                        PContactLogAccess.DeleteByPrimaryKey(ContactLogId, Transaction);
                    }

                    SubmissionOK = true;
                }
            });
        }
Example #2
0
        public static void DeleteContacts(
            DataTable AContactLogs)
        {
            TDBTransaction Transaction  = null;
            bool           SubmissionOK = false;

            DBAccess.GDBAccessObj.GetNewOrExistingAutoTransaction(IsolationLevel.Serializable,
                                                                  ref Transaction,
                                                                  ref SubmissionOK,
                                                                  delegate
            {
                foreach (DataRow contactLogRow in AContactLogs.Rows)
                {
                    PPartnerContactTable contactLogs = PPartnerContactAccess.LoadByPrimaryKey(
                        Convert.ToInt64(contactLogRow["p_partner_key_n"]), Convert.ToInt64(contactLogRow["p_contact_log_id_i"]), Transaction);

                    contactLogs[0].Delete();

                    PPartnerContactAccess.SubmitChanges(contactLogs, Transaction);

                    SubmissionOK = true;
                }
            });
        }