Example #1
0
        protected void SaveRecord(bool newRecord)
        {
            // new record / exiting record //

            object oldEntity = null;

            if (newRecord)
            {
                PersonOrganisation              = new CRM_PersonOrganisation();
                PersonOrganisation.IsArchived   = false;
                PersonOrganisation.CRM_PersonID = Entity.ID;
                db.CRM_PersonOrganisations.InsertOnSubmit(PersonOrganisation);
            }
            else
            {
                oldEntity = PersonOrganisation.ShallowCopy();
            }

            PersonOrganisation.Telephone        = txtTelephone.Text;
            PersonOrganisation.Email            = txtEmail.Text;
            PersonOrganisation.CRM_Organisation = db.CRM_Organisations.Single(o => o.Reference == ucACOrganisation.SelectedID);
            PersonOrganisation.CRM_Role         = db.CRM_Roles.Single(r => r.ID.ToString() == ddlRole.SelectedValue);

            db.SubmitChanges();

            if (oldEntity != null)
            {
                CRM.Code.History.History.RecordLinqUpdate(db, AdminUser, oldEntity, PersonOrganisation);
                db.SubmitChanges();
            }
            else
            {
                CRM.Code.History.History.RecordLinqInsert(AdminUser, PersonOrganisation);
            }
        }