/// <summary>
    /// OnAfterSave handler.
    /// </summary>
    private void editProfileForm_OnAfterSave(object sender, EventArgs e)
    {
        // Update current contact info
        var classInfo = DataClassInfoProvider.GetDataClassInfo(editProfileForm.ClassName);

        ContactInfoProvider.UpdateContactFromExternalData(editProfileForm.Info, classInfo.ClassContactOverwriteEnabled, ModuleCommands.OnlineMarketingGetCurrentContactID());
    }
Ejemplo n.º 2
0
    /// <summary>
    /// Merge contact with customer and creates relation between these two.
    /// </summary>
    /// <param name="customerInfo">Registered customer to merge with proper contact</param>
    private void CreateContactRelation(CustomerInfo customerInfo)
    {
        int contactId = ModuleCommands.OnlineMarketingGetCurrentContactID();

        ModuleCommands.OnlineMarketingCreateRelation(customerInfo.CustomerID, MembershipType.ECOMMERCE_CUSTOMER, contactId);
        ContactInfoProvider.UpdateContactFromExternalData(
            customerInfo,
            DataClassInfoProvider.GetDataClassInfo(CustomerInfo.TYPEINFO.ObjectClassName).ClassContactOverwriteEnabled,
            contactId);
    }
Ejemplo n.º 3
0
        private void SetCustomerRelationAndUpdateContact(CustomerInfo customerInfo)
        {
            if (mCurrentContactProvider == null)
            {
                return;
            }

            var currentContact = mCurrentContactProvider.GetCurrentContact(MembershipContext.AuthenticatedUser, false);

            mCurrentContactProvider.SetCurrentContact(currentContact);

            Service.Entry <IContactRelationAssigner>().Assign(MemberTypeEnum.EcommerceCustomer, customerInfo, currentContact, true);
            ContactInfoProvider.UpdateContactFromExternalData(
                customerInfo,
                DataClassInfoProvider.GetDataClassInfo(CustomerInfo.TYPEINFO.ObjectClassName).ClassContactOverwriteEnabled,
                currentContact.ContactID);
        }
    /// <summary>
    /// Sets data to database.
    /// </summary>
    protected void btnOK_Click(object sender, EventArgs e)
    {
        string errorMessage = "";
        string siteName     = SiteContext.CurrentSiteName;

        if ((txtCustomerCompany.Text.Trim() == "" || !IsBusiness) &&
            ((txtCustomerFirstName.Text.Trim() == "") || (txtCustomerLastName.Text.Trim() == "")))
        {
            errorMessage = GetString("Customers_Edit.errorInsert");
        }

        // At least company name has to be filled when company account is selected
        if (errorMessage == "" && IsBusiness)
        {
            errorMessage = new Validator().NotEmpty(txtCustomerCompany.Text, GetString("customers_edit.errorCompany")).Result;
        }

        // Check the following items if complete company info is required for company account
        if (errorMessage == "" && ECommerceSettings.RequireCompanyInfo(siteName) && IsBusiness)
        {
            errorMessage = new Validator().NotEmpty(txtOraganizationID.Text, GetString("customers_edit.errorOrganizationID"))
                           .NotEmpty(txtTaxRegistrationID.Text, GetString("customers_edit.errorTaxRegID")).Result;
        }

        if (errorMessage == "")
        {
            errorMessage = new Validator().IsEmail(txtCustomerEmail.Text.Trim(), GetString("customers_edit.erroremailformat"), true)
                           .MatchesCondition(txtCustomerPhone.Text.Trim(), k => k.Length < 50, GetString("customers_edit.errorphoneformat")).Result;
        }

        plcCompanyInfo.Visible = IsBusiness;

        if (errorMessage == "")
        {
            // If customer doesn't already exist, create new one
            if (mCustomer == null)
            {
                mCustomer = new CustomerInfo();
                mCustomer.CustomerUserID = MembershipContext.AuthenticatedUser.UserID;
            }

            mCustomer.CustomerEmail     = txtCustomerEmail.Text.Trim();
            mCustomer.CustomerLastName  = txtCustomerLastName.Text.Trim();
            mCustomer.CustomerPhone     = txtCustomerPhone.Text.Trim();
            mCustomer.CustomerFirstName = txtCustomerFirstName.Text.Trim();
            mCustomer.CustomerCreated   = DateTime.Now;

            if (IsBusiness)
            {
                mCustomer.CustomerCompany           = txtCustomerCompany.Text.Trim();
                mCustomer.CustomerOrganizationID    = txtOraganizationID.Text.Trim();
                mCustomer.CustomerTaxRegistrationID = txtTaxRegistrationID.Text.Trim();
            }
            else
            {
                mCustomer.CustomerCompany           = "";
                mCustomer.CustomerOrganizationID    = "";
                mCustomer.CustomerTaxRegistrationID = "";
            }

            // Update customer data
            CustomerInfoProvider.SetCustomerInfo(mCustomer);

            // Update corresponding contact data
            int currentContactId = ModuleCommands.OnlineMarketingGetCurrentContactID();
            ModuleCommands.OnlineMarketingCreateRelation(mCustomer.CustomerID, MembershipType.ECOMMERCE_CUSTOMER, currentContactId);
            ContactInfoProvider.UpdateContactFromExternalData(
                mCustomer,
                DataClassInfoProvider.GetDataClassInfo(CustomerInfo.TYPEINFO.ObjectClassName).ClassContactOverwriteEnabled,
                currentContactId);

            // Let others now that customer was created
            if (OnCustomerCrated != null)
            {
                OnCustomerCrated();

                ShowChangesSaved();
            }
            else
            {
                URLHelper.Redirect(URLHelper.AddParameterToUrl(RequestContext.CurrentURL, "saved", "1"));
            }
        }
        else
        {
            //Show error
            ShowError(errorMessage);
        }
    }