Пример #1
0
        private void simpleButtonSave_Click(object sender, EventArgs e)
        {
            if (textEditFirstname.Text.Length < 1 || textEditLastname.Text.Length < 1) {
                MessageBox.Show("Firstname / Lastname is required.", "Add Contact", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                DialogResult = System.Windows.Forms.DialogResult.None;
                return;
            }
            bool IsActivated = false;
            BPContext = new BrightPlatformEntities(UserSession.EntityConnection);

            contact objContact = ObjectContact.GetContact(textEditFirstname.Text, textEditLastname.Text, m_accountID);
            if (objContact != null) {
                if (!m_Edit && !objContact.active) {
                    string Message = "This contact is currently de-activated." + Environment.NewLine + "Would you like to re-activate this contact?";
                    DialogResult objResult = MessageBox.Show(Message, "Add Contact", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (objResult == DialogResult.Yes) {
                        var objC = BPContext.contacts.FirstOrDefault(x=>x.id == objContact.id);
                        objC.active = true;
                        BPContext.SaveChanges();
                        DialogResult = System.Windows.Forms.DialogResult.OK;
                        return;
                    } else {
                        DialogResult = System.Windows.Forms.DialogResult.None;
                        return;
                    }
                } else if (m_Edit && !objContact.active) {
                    string Message = "Contact already exist and is currently de-activated, please enter another contact name.";
                    MessageBox.Show(Message, "Add Contact", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                    DialogResult = System.Windows.Forms.DialogResult.None;
                    return;
                }else {
                    MessageBox.Show("Contact already exist, please enter another contact name.", "Contacts", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                    DialogResult = System.Windows.Forms.DialogResult.None;
                    return;
                }
            }

            var titleval = ComboBoxAuto.Tag as object[];
            int? title_id = null;
            /**
             * [@jeff 05.24.2012]: https://brightvision.jira.com/browse/PLATFORM-1433
             * added validation for null titleval
             */
            if (titleval != null)
                if (titleval.Length > 0)
                    title_id = titleval[0] != null ? (int?) int.Parse(titleval[0].ToString()) : null;

            int? contact_id;

            if (m_Edit) {
                BPContext.FIUpdateContactDetails(
                    objContact.id, textEditFirstname.Text.Trim(), textEditMiddlename.Text.Trim(), textEditLastname.Text.Trim(),
                    textEditDirectphone.Text.Trim(), textEditMobile.Text.Trim(), title_id, null, textEditRoles.Text.Trim(),
                    textEditAddress1.Text.Trim(), textEditAddress2.Text.Trim(), textEditCity.Text.Trim(),
                    textEditZip.Text.Trim(), textEditCountry.Text.Trim(), "", UserSession.CurrentUser.UserId,
                    textEditEmail.Text.Trim(), "", 0, IsActivated, m_accountID, null,
                    UserSession.CurrentUser.ComputerName,
                    BrightVision.EventLog.Business.FacadeEventLog.Source_Bright_Manager_Add_Contact,
                    null,
                    null,
                    null,
                    null
                );
            } else {
                contact_id = BPContext.FIUpdateContactDetails(
                        null, textEditFirstname.Text.Trim(), textEditMiddlename.Text.Trim(), textEditLastname.Text.Trim(),
                        textEditDirectphone.Text.Trim(), textEditMobile.Text.Trim(), title_id, null, textEditRoles.Text.Trim(),
                        textEditAddress1.Text.Trim(), textEditAddress2.Text.Trim(), textEditCity.Text.Trim(),
                        textEditZip.Text.Trim(), textEditCountry.Text.Trim(), "", UserSession.CurrentUser.UserId,
                        textEditEmail.Text.Trim(), "", 0, true , m_accountID, null,
                        UserSession.CurrentUser.ComputerName,
                        BrightVision.EventLog.Business.FacadeEventLog.Source_Bright_Manager_Add_Contact,
                        null,
                        null,
                        null,
                        null
                ).FirstOrDefault();

                ContactId = contact_id ?? 0;
            }
        }
Пример #2
0
        /// <summary>
        /// Save contact record
        /// </summary>
        public static void SaveContacts(List<CTContact> aContactList, int pContactId, string pModifiedSource)
        {
            BrightPlatformEntities m_objBrightPlatformEntity = new BrightPlatformEntities(UserSession.EntityConnection);
            foreach (CTContact iContact in aContactList) {
                if (iContact == null)
                    continue;

                m_objBrightPlatformEntity.FIUpdateContactDetails (
                    iContact.id,
                    iContact.first_name,
                    iContact.middle_name,
                    iContact.last_name,
                    iContact.direct_phone,
                    iContact.mobile,
                    null,
                    iContact.title,
                    iContact.role_tags,
                    iContact.address_1,
                    iContact.address_2,
                    iContact.city,
                    iContact.zipcode,
                    iContact.country,
                    "",
                    UserSession.CurrentUser.UserId,
                    iContact.email,
                    iContact.linkedin_url,
                    null,
                    true,
                    pContactId,
                    null,
                    UserSession.CurrentUser.ComputerName,
                    pModifiedSource,
                    iContact.absence_start,
                    iContact.absence_end,
                    null,
                    null
                );

                //var objContact = m_objBrightPlatformEntity.contacts.Where(objRow => objRow.id == iContact.id).SingleOrDefault();
                //objContact.first_name = iContact.first_name;
                //objContact.middle_name = iContact.middle_name;
                //objContact.last_name = iContact.last_name;
                //objContact.direct_phone = iContact.direct_phone;
                //objContact.mobile = iContact.mobile;
                //objContact.email = iContact.email;
                //objContact.title = iContact.title;
                ////objContact.company_name = iContact.company_name;
                //objContact.address_1 = iContact.address_1;
                //objContact.address_2 = iContact.address_2;
                //objContact.city = iContact.city;
                //objContact.zipcode = iContact.zipcode;
                //objContact.country = iContact.country;
                //objContact.active = iContact.active;
                //m_objBrightPlatformEntity.SaveChanges();
            }
        }