protected void btnSubmitChanges_Click(object sender, EventArgs e) { if (hdnRecord.Value != "") { object oldEntity = null; object oldAddress = null; CRM.Code.Models.CRM_Person person = db.CRM_Persons.Single(s => s.ID.ToString() == hdnRecord.Value); oldEntity = person.ShallowCopy(); oldAddress = person.CRM_Address.ShallowCopy(); TransformPerson(person); person.WebsiteAccountID = Entity.OriginAccountID; person.Password = Entity.Password; if (Entity.GroupNames.Length > 0) { var groupNames = Entity.GroupNames.Split(new string[] { Environment.NewLine }, StringSplitOptions.None); foreach (var groupName in groupNames) { if (groupName.Trim().Length > 0) { } } } if (Entity.DoNotMail != null) { person.IsDoNotMail = (bool)Entity.DoNotMail; } if (Entity.DoNotEmail != null) { person.IsDoNotEmail = (bool)Entity.DoNotEmail; } /* * if (Entity.AlwaysSendPassInfo != null) * person.AlwaysSendPassInfo = (bool)Entity.AlwaysSendPassInfo; */ db.SubmitChanges(); CRM.Code.History.History.RecordLinqUpdate(AdminUser, oldEntity, person); CRM.Code.History.History.RecordLinqUpdate(AdminUser, oldAddress, person.PrimaryAddress); db.SubmitChanges(); ApplyCustomField(person, 2, 22); db.SubmitChanges(); ApplyConstituentsToSelected(person); /* * * CRM_FormFieldAnswer answer = db.CRM_FormFieldAnswers.FirstOrDefault(f => f.CRM_FormFieldID == 24 && f.TargetReference == person.Reference); * * if (answer == null) * { * answer = new CRM_FormFieldAnswer(); * answer.CRM_FormFieldID = 24; * answer.TargetReference = person.Reference; * db.CRM_FormFieldAnswers.InsertOnSubmit(answer); * } * * answer.Answer = ""; * foreach (ListItem chkBox in rptInterests.Items) * { * if (chkBox.Selected) * { * string id = chkBox.Value; * CRM_FormFieldItem item = db.CRM_FormFieldItems.Single(s => s.ID.ToString() == id); * answer.Answer += item.Label + "<br/>"; * } * } * */ AddRelationship(person); db.SubmitChanges(); NoticeManager.SetMessage("Record merged"); } }
protected void SaveRecord(bool newRecord) { // new record / exiting record // object oldEntity = null; object oldAddress = null; if (newRecord) { Entity = new CRM_Person(); Entity.IsArchived = false; Entity.DateAdded = UKTime.Now; Entity.Password = ""; Entity.TempCode = ""; db.CRM_Persons.InsertOnSubmit(Entity); } else { oldEntity = Entity.ShallowCopy(); oldAddress = Entity.CRM_Address.ShallowCopy(); } Entity.DateModified = UKTime.Now; Entity.Title = ddlTitles.SelectedValue; Entity.Firstname = txtFirstname.Text; Entity.Lastname = txtLastname.Text; Entity.PreviousNames = txtPrevious.Text; Entity.PrimaryEmail = txtPrimaryEmail.Text; Entity.PrimaryTelephone = txtTelephone.Text; Entity.IsContactEmail = chkIsContactEmail.Checked; Entity.IsChild = chkIsChild.Checked; Entity.IsConcession = chkIsConcession.Checked; Entity.IsCarerMinder = chkIsCarerMinder.Checked; Entity.IsDeceased = chkIsDeceased.Checked; Entity.IsGiftAid = chkIsGiftAid.Checked; Entity.IsDoNotMail = chkIsDoNotMail.Checked; Entity.IsDoNotEmail = chkIsDoNotEmail.Checked; Entity.AddressType = (byte)CRM_Address.Types.Home; Entity.Telephone2 = txtTelephone2.Text; if (!String.IsNullOrEmpty(txtDateOfBirth.Text)) { Entity.DateOfBirth = txtDateOfBirth.Value; } if (newRecord) { CRM_Address address = new CRM_Address(); Entity.CRM_Address = (CRM_Address)((Address)ucAddress).Save(address); } else { Entity.CRM_Address = (CRM_Address)((Address)ucAddress).Save(Entity.CRM_Address); } db.SubmitChanges(); if (ddlPrimaryAddress.SelectedValue != "") { Entity.PrimaryAddressID = Convert.ToInt32(ddlPrimaryAddress.SelectedValue); } db.SubmitChanges(); Entity.CRM_Address.ParentID = Entity.ID; if (oldEntity != null) { CRM.Code.History.History.RecordLinqUpdate(AdminUser, oldEntity, Entity); CRM.Code.History.History.RecordLinqUpdate(AdminUser, oldAddress, Entity.CRM_Address); db.SubmitChanges(); } else { CRM.Code.History.History.RecordLinqInsert(AdminUser, Entity); CRM.Code.History.History.RecordLinqInsert(AdminUser, Entity.CRM_Address); } ucCustomFields.Save(Entity.Reference); if (hdnCaptured.Value == "1") { File.Copy(MapPath(AdminUser.TempPhotoFile), MapPath(Entity.PersonImageURL), true); } }