示例#1
0
        bool DoRegisterOrUpdate(bool IsUpdate, bool RequiresPopup = true)
        {
            var ToUpdate = Innovaction.WSManager.EmptyCustomer(PortalId);

            #region datos personales
            ToUpdate.fistName = tx_FirstName.Text;
            ToUpdate.lastName = tx_FirstSurname.Text;

            ToUpdate.gender            = dd_Gender.SelectedValue;
            ToUpdate.birthDay          = dd_BirthDate.SelectedValue;
            ToUpdate.birthDaySpecified = true;
            ToUpdate.nickname          = tx_Email.Text;


            // ci
            ToUpdate.nationalId = tx_CI.Text;

            if ((!String.IsNullOrEmpty(tx_CustomerID.Text)) && (IsUpdate))
            {
                try
                {
                    ToUpdate.id = Convert.ToInt32(tx_CustomerID.Text);
                }
                catch { }
                ToUpdate.idSpecified = true;
            }
            //else
            //{
            //    ToUpdate.id = Convert.ToInt32(tx_CustomerID.Text);
            //}

            ToUpdate.password = tx_Password.Text;

            // celular
            if (!String.IsNullOrEmpty(tx_CellPhone.Text))
            {
                ToUpdate.phone = new Innovaction.CustomerDataWS.phoneTo[1];
                var Phone = new Innovaction.CustomerDataWS.phoneTo();
                ToUpdate.phone[0]  = Phone;
                Phone.numberNew    = tx_CellPhone.Text;
                Phone.phoneType    = new Innovaction.CustomerDataWS.phoneTypeTo();
                Phone.phoneType.id = "MOBILE";
                if (IsUpdate)
                {
                    Phone.operationType = Innovaction.CustomerDataWS.operationType.UPDATE;
                }
                else
                {
                    Phone.operationType = Innovaction.CustomerDataWS.operationType.INSERT;
                }
                Phone.operationTypeSpecified = true;
                Phone.primary = true;
            }


            #endregion

            if (IsUpdate)
            {
                // en realidad es un update mentiroso, por que nada de esta informacion existe..


                #region direccion

                // aparentemente tenemos que borrar las direcciones
                ToUpdate.address = new Innovaction.CustomerDataWS.addressTo[2];
                // borro el viejo


                //int atmpIndex = 0;
                //foreach (ListItem addtype in dd_Address.Items)
                //{
                //    if (!addtype.Selected)
                //    {
                var AddressToDelete = new Innovaction.CustomerDataWS.addressTo();
                AddressToDelete.operationType          = Innovaction.CustomerDataWS.operationType.DELETE;
                AddressToDelete.operationTypeSpecified = true;
                AddressToDelete.addressType            = new Innovaction.CustomerDataWS.addressTypeTo();
                AddressToDelete.addressType.id         = "HOME";
                AddressToDelete.city          = new Innovaction.CustomerDataWS.cityTo();
                AddressToDelete.city.id       = dd_City.SelectedValue;
                AddressToDelete.city.state    = new Innovaction.CustomerDataWS.stateTo();
                AddressToDelete.city.state.id = dd_State.SelectedValue;
                // portal id
                AddressToDelete.city.state.country    = new Innovaction.CustomerDataWS.countryTo();
                AddressToDelete.city.state.country.id = Innovaction.WSManager.CountryID(PortalId);
                ToUpdate.address[0] = AddressToDelete;

                //        atmpIndex++;
                //    }

                //}


                // finalmente insertamos la nuestra
                var Address = new Innovaction.CustomerDataWS.addressTo();
                Address.operationTypeSpecified = true;
                Address.primary       = true;
                Address.operationType = Innovaction.CustomerDataWS.operationType.UPDATE;

                Address.addressType    = new Innovaction.CustomerDataWS.addressTypeTo();
                Address.addressType.id = "HOME";

                var Ciudad = new Innovaction.CustomerDataWS.cityTo();
                Ciudad.id = dd_City.SelectedValue;
                var State = new Innovaction.CustomerDataWS.stateTo();
                State.id = dd_State.SelectedValue;
                var Country = new Innovaction.CustomerDataWS.countryTo();
                // portal id
                Country.id    = Innovaction.WSManager.CountryID(PortalId);
                State.country = Country;
                Ciudad.state  = State;
                Address.city  = Ciudad;

                ToUpdate.address[1] = Address;


                #endregion

                #region otros datos
                ToUpdate.nationality    = new Innovaction.CustomerDataWS.countryTo();
                ToUpdate.nationality.id = dd_Country.SelectedValue;


                //ToUpdate.occupation = new Innovaction.CustomerDataWS.occupationTo();
                //ToUpdate.occupation.id = dd_Jobs.SelectedValue;

                //ToUpdate.childQty = Kid_DynamicAddControl.ChildControlList.Count;
                //ToUpdate.childQtySpecified = true;
                var ControlList = GetChildControlList();
                ToUpdate.children = new Innovaction.CustomerDataWS.customerChildTo[ControlList.Count];
                int tmpChild = 0;
                foreach (ChildrenControl elControl in ControlList)
                {
                    //leo la info de cada control
                    ToUpdate.children[tmpChild] = new Innovaction.CustomerDataWS.customerChildTo();
                    var Child = ToUpdate.children[tmpChild];
                    Child.customerChildNoSpecified = true;


                    if ((elControl.Visible == false) && (!elControl.IsNew))
                    {
                        Child.operationType   = Innovaction.CustomerDataWS.operationType.DELETE;
                        Child.customerChildNo = elControl.SelectedKid;
                    }
                    else if (elControl.IsNew)
                    {
                        Child.customerChildNo = tmpChild;
                        Child.operationType   = Innovaction.CustomerDataWS.operationType.INSERT;
                    }

                    Child.operationTypeSpecified = true;



                    Child.birthDateSpecified = true;
                    ToUpdate.children[tmpChild].birthDate = elControl.SelectedDate;


                    if (elControl.SelectedGender == "F")
                    {
                        ToUpdate.children[tmpChild].gender = Innovaction.CustomerDataWS.gender.F;
                    }
                    else
                    {
                        ToUpdate.children[tmpChild].gender = Innovaction.CustomerDataWS.gender.M;
                    }

                    ToUpdate.children[tmpChild].genderSpecified = true;


                    //  elControl.SelectedGender;
                    tmpChild++;
                }


                #endregion
            }
            #region preferencias de envio
            // siempre vamos a mandarle las preferencias de envio, queremos que el default sea todo prendido


            ToUpdate.communicationAllowanceSpecified = true;
            //var AllowPreferences = Convert.ToBoolean(rb_info.SelectedValue);
            //ToUpdate.communicationAllowance = AllowPreferences;
            // preferences
            // topics!
            ToUpdate.communicationPreference = new CustomerDataWS.communicationPreferenceTo();
            if (chbx_Topics.Items.Count > 0)
            {
                ToUpdate.communicationPreference.topics = new Innovaction.CustomerDataWS.topicTo[chbx_Topics.Items.Count];


                int tmpIndex = 0;
                foreach (ListItem TheTopic in chbx_Topics.Items)
                {
                    var Topic = new Innovaction.CustomerDataWS.topicTo();
                    Topic.id     = TheTopic.Value;
                    Topic.active = TheTopic.Selected;
                    Topic.operationTypeSpecified = true;
                    if (TheTopic.Selected)
                    {
                        Topic.operationType = Innovaction.CustomerDataWS.operationType.INSERT;
                    }
                    else
                    {
                        Topic.operationType = Innovaction.CustomerDataWS.operationType.DELETE;
                    }
                    ToUpdate.communicationPreference.topics[tmpIndex] = Topic;
                    tmpIndex++;
                }
            }
            //fequency
            // tengo que recorrerlos 1 por 1 por que los tienen en un valor de array separado si uso insert.. tengo q borrar y insertar el nuevo
            ToUpdate.communicationPreference.frequencies = new Innovaction.CustomerDataWS.frequencyTo[rb_Frequency.Items.Count];
            int tmpFCount = 0;
            foreach (ListItem TheFrequency in rb_Frequency.Items)
            {
                var Frequency = new Innovaction.CustomerDataWS.frequencyTo();
                Frequency.id = TheFrequency.Value;
                if (TheFrequency.Selected)
                {
                    Frequency.operationType = Innovaction.CustomerDataWS.operationType.INSERT;
                }
                else
                {
                    Frequency.operationType = Innovaction.CustomerDataWS.operationType.DELETE;
                }
                Frequency.operationTypeSpecified = true;
                Frequency.active = true;


                ToUpdate.communicationPreference.frequencies[tmpFCount] = Frequency;
                tmpFCount++;
            }

            // channel
            // mismo caso que la frequency..

            ToUpdate.communicationPreference.channels = new Innovaction.CustomerDataWS.channelTo[rb_Channel.Items.Count];
            int tmpCounter = 0;
            foreach (ListItem TheChannel in rb_Channel.Items)
            {
                var Channel = new Innovaction.CustomerDataWS.channelTo();
                Channel.id = TheChannel.Value;
                if (TheChannel.Selected)
                {
                    Channel.operationType = Innovaction.CustomerDataWS.operationType.INSERT;
                }
                else
                {
                    Channel.operationType = Innovaction.CustomerDataWS.operationType.DELETE;
                }
                Channel.operationTypeSpecified = true;
                Channel.active = true;


                ToUpdate.communicationPreference.channels[tmpCounter] = Channel;
                tmpCounter++;
            }

            #endregion



            // we update the customer
            var respuesta = new Innovaction.CustomerDataWS.customerResponse();
            if (IsUpdate)
            {
                respuesta = Innovaction.WSManager.UpdateCustomer(ToUpdate, PortalId);


                if (respuesta.responseCode == CustomerDataWS.responseCode.SUCCESS)
                {
                    if (RequiresPopup)
                    {
                        DnnAlert("Muchas gracias, sus datos han sido actualizados.", 300);
                    }
                    return(true);
                }
                else
                {
                    if (RequiresPopup)
                    {
                        DnnAlert("Error al actualizar el usuario: " + respuesta.responseMessage, 300);
                    }
                    return(false);
                }
            }
            // la primera vez guardamos, no es un update!
            else
            {
                respuesta = Innovaction.WSManager.CreateCustomer(ToUpdate, PortalId);

                if (respuesta.responseCode == CustomerDataWS.responseCode.SUCCESS)
                {
                    if (RequiresPopup)
                    {
                        DnnAlert("Muchas gracias por registrarte, te invitamos a llenar algunos datos adicionales para conocerte un poco más.", 400);
                    }

                    tx_CustomerID.Text = respuesta.customer.id.ToString();
                    return(true);
                }
                else
                {
                    if (RequiresPopup)
                    {
                        DnnAlert("Error al crear el usuario: " + respuesta.responseMessage, 300);
                    }

                    return(false);
                }
            }


            // response output debugg.
        }
示例#2
0
        protected void ActualizarButton_Click(object sender, EventArgs e)
        {
            // como deberia ser
            var ToUpdate = Innovaction.WSManager.EmptyCustomer(ThePortalID);

            // para debuguear:
            if (Debugging)
            {
                ToUpdate = Innovaction.WSManager.GetFullCustomer(Innovaction.WSManager.ValidateLogin("*****@*****.**", "farmatodo123", ThePortalID).customer, ThePortalID).customer;
            }
            // end debug

            ToUpdate.id          = Convert.ToInt32(tx_CustomerID.Text);
            ToUpdate.idSpecified = true;
            ToUpdate.nationalId  = tx_NationalID.Text;

            #region datos personales
            ToUpdate.fistName   = tx_FirstName.Text;
            ToUpdate.middleName = tx_SecondName.Text;
            ToUpdate.lastName   = tx_FirstSurname.Text;
            ToUpdate.surname    = tx_SecondSurname.Text;
            ToUpdate.gender     = dd_Gender.SelectedValue;
            // fuera del sistema, no se puede actualizar! shiradit
            //ToUpdate.nationalId = dd_CI.SelectedValue + "-" + tx_CI.Text;
            ToUpdate.birthDay = dd_BirthDate.SelectedValue;

            ToUpdate.birthDaySpecified = true;



            //   ToUpdate.nickname = tx_Email.Text;

            //ToUpdate.socialNetwork[0].idNew = tx_Twitter.Text;
            //ToUpdate.socialNetwork[1].idNew = tx_Facebook.Text;

            ToUpdate.maritalStatus    = new Innovaction.CustomerDataWS.maritalStatusTo();
            ToUpdate.maritalStatus.id = dd_MatrialState.SelectedValue;

            // de aca para adelante necesitan del old id para poder actualizar u.u

            // redes sociales, twiter y facebok
            ToUpdate.socialNetwork = new Innovaction.CustomerDataWS.socialNetworkTo[2];
            var FacebookSN = new Innovaction.CustomerDataWS.socialNetworkTo();
            var TwitterSN  = new Innovaction.CustomerDataWS.socialNetworkTo();
            ToUpdate.socialNetwork[0] = FacebookSN;
            ToUpdate.socialNetwork[1] = TwitterSN;

            FacebookSN.idNew = tx_Facebook.Text;
            if (String.IsNullOrEmpty(tx_Facebook.Text))
            {
                FacebookSN.operationType = Innovaction.CustomerDataWS.operationType.DELETE;
            }
            else
            {
                FacebookSN.operationType = Innovaction.CustomerDataWS.operationType.UPDATE;
            }
            FacebookSN.operationTypeSpecified = true;
            FacebookSN.socialNetworkType      = new Innovaction.CustomerDataWS.socialNetworkTypeTo();
            FacebookSN.socialNetworkType.type = "FB";
            FacebookSN.primary   = true;
            FacebookSN.validated = false;
            FacebookSN.idOld     = tx_FacebookOLD.Text;

            TwitterSN.idNew = tx_Twitter.Text;
            if (String.IsNullOrEmpty(tx_Twitter.Text))
            {
                TwitterSN.operationType = Innovaction.CustomerDataWS.operationType.DELETE;
            }
            else
            {
                TwitterSN.operationType = Innovaction.CustomerDataWS.operationType.UPDATE;
            }

            TwitterSN.operationTypeSpecified = true;
            TwitterSN.socialNetworkType      = new Innovaction.CustomerDataWS.socialNetworkTypeTo();
            TwitterSN.socialNetworkType.type = "TW";
            TwitterSN.validated = false;
            TwitterSN.primary   = true;
            TwitterSN.idOld     = tx_TwitterOLD.Text;

            // celular
            ToUpdate.phone = new Innovaction.CustomerDataWS.phoneTo[1];
            var Phone = new Innovaction.CustomerDataWS.phoneTo();
            ToUpdate.phone[0]  = Phone;
            Phone.numberNew    = tx_CellPhone.Text;
            Phone.phoneType    = new Innovaction.CustomerDataWS.phoneTypeTo();
            Phone.phoneType.id = "MOBILE";
            if (String.IsNullOrEmpty(tx_CellPhone.Text))
            {
                Phone.operationType = Innovaction.CustomerDataWS.operationType.DELETE;
            }
            else
            {
                Phone.operationType = Innovaction.CustomerDataWS.operationType.UPDATE;
            }
            Phone.operationTypeSpecified = true;
            Phone.primary   = true;
            Phone.numberOld = tx_CellPhoneOLD.Text;


            #endregion

            #region direccion
            // aparentemente tenemos que borrar las direcciones
            ToUpdate.address = new Innovaction.CustomerDataWS.addressTo[2];
            // borro el viejo


            //int atmpIndex = 0;
            //foreach (ListItem addtype in dd_Address.Items)
            //{
            //    if (!addtype.Selected)
            //    {
            var AddressToDelete = new Innovaction.CustomerDataWS.addressTo();
            AddressToDelete.operationType          = Innovaction.CustomerDataWS.operationType.DELETE;
            AddressToDelete.operationTypeSpecified = true;
            AddressToDelete.addressType            = new Innovaction.CustomerDataWS.addressTypeTo();
            AddressToDelete.addressType.id         = tx_AddressOLD.Text;
            AddressToDelete.city          = new Innovaction.CustomerDataWS.cityTo();
            AddressToDelete.city.id       = tx_CityOLD.Text;
            AddressToDelete.city.state    = new Innovaction.CustomerDataWS.stateTo();
            AddressToDelete.city.state.id = tx_StateOLD.Text;
            // portal id
            AddressToDelete.city.state.country    = new Innovaction.CustomerDataWS.countryTo();
            AddressToDelete.city.state.country.id = "VE";
            ToUpdate.address[0] = AddressToDelete;

            //        atmpIndex++;
            //    }

            //}


            // finalmente insertamos la nuestra
            var Address = new Innovaction.CustomerDataWS.addressTo();
            Address.operationTypeSpecified = true;
            Address.primary       = true;
            Address.operationType = Innovaction.CustomerDataWS.operationType.UPDATE;

            Address.addressType    = new Innovaction.CustomerDataWS.addressTypeTo();
            Address.addressType.id = dd_Address.SelectedValue;

            var Ciudad = new Innovaction.CustomerDataWS.cityTo();
            Ciudad.id = dd_City.SelectedValue;
            var State = new Innovaction.CustomerDataWS.stateTo();
            State.id = dd_State.SelectedValue;
            var Country = new Innovaction.CustomerDataWS.countryTo();
            // portal id
            Country.id             = Innovaction.WSManager.CountryID(PortalId);
            State.country          = Country;
            Ciudad.state           = State;
            Address.city           = Ciudad;
            Address.municipality   = tx_Municipio.Text;
            Address.buildingHome   = tx_Building.Text;
            Address.floor          = tx_floor.Text;
            Address.apartmentHome  = tx_apartmentNumber.Text;
            Address.street         = tx_Street.Text;
            Address.neighborhood   = tx_Urban.Text;
            Address.referencePoint = tx_RefPoint.Text;
            Address.zipCode        = tx_CP.Text;
            ToUpdate.address[1]    = Address;


            #endregion

            #region otros datos
            ToUpdate.nationality    = new Innovaction.CustomerDataWS.countryTo();
            ToUpdate.nationality.id = dd_Country.SelectedValue;


            ToUpdate.occupation    = new Innovaction.CustomerDataWS.occupationTo();
            ToUpdate.occupation.id = dd_Jobs.SelectedValue;

            //ToUpdate.childQty = Kid_DynamicAddControl.ChildControlList.Count;
            //ToUpdate.childQtySpecified = true;
            var ControlList = GetChildControlList();
            ToUpdate.children = new Innovaction.CustomerDataWS.customerChildTo[ControlList.Count];
            int tmpChild = 0;
            foreach (ChildrenControl elControl in ControlList)
            {
                //leo la info de cada control
                ToUpdate.children[tmpChild] = new Innovaction.CustomerDataWS.customerChildTo();
                var Child = ToUpdate.children[tmpChild];
                Child.customerChildNoSpecified = true;


                if ((elControl.Visible == false) && (!elControl.IsNew))
                {
                    Child.operationType   = Innovaction.CustomerDataWS.operationType.DELETE;
                    Child.customerChildNo = elControl.SelectedKid;
                }
                else if (elControl.IsNew)
                {
                    Child.customerChildNo = tmpChild;
                    Child.operationType   = Innovaction.CustomerDataWS.operationType.INSERT;
                }

                Child.operationTypeSpecified = true;



                Child.birthDateSpecified = true;
                ToUpdate.children[tmpChild].birthDate = elControl.SelectedDate;


                if (elControl.SelectedGender == "F")
                {
                    ToUpdate.children[tmpChild].gender = Innovaction.CustomerDataWS.gender.F;
                }
                else
                {
                    ToUpdate.children[tmpChild].gender = Innovaction.CustomerDataWS.gender.M;
                }

                ToUpdate.children[tmpChild].genderSpecified = true;


                //  elControl.SelectedGender;
                tmpChild++;
            }


            #endregion

            #region preferencias de envio
            // shiradit dijo que para esta seccion nbo usamos update, sino que insert y delete -.-


            ToUpdate.communicationAllowanceSpecified = true;
            //var AllowPreferences = Convert.ToBoolean(rb_info.SelectedValue);
            //ToUpdate.communicationAllowance = AllowPreferences;
            // preferences
            // topics!
            ToUpdate.communicationPreference = new CustomerDataWS.communicationPreferenceTo();
            if (chbx_Topics.Items.Count > 0)
            {
                ToUpdate.communicationPreference.topics = new Innovaction.CustomerDataWS.topicTo[chbx_Topics.Items.Count];

                int tmpIndex = 0;
                foreach (ListItem TheTopic in chbx_Topics.Items)
                {
                    var Topic = new Innovaction.CustomerDataWS.topicTo();
                    Topic.id     = TheTopic.Value;
                    Topic.active = TheTopic.Selected;
                    Topic.operationTypeSpecified = true;
                    if (TheTopic.Selected)
                    {
                        Topic.operationType = Innovaction.CustomerDataWS.operationType.INSERT;
                    }
                    else
                    {
                        Topic.operationType = Innovaction.CustomerDataWS.operationType.DELETE;
                    }
                    ToUpdate.communicationPreference.topics[tmpIndex] = Topic;
                    tmpIndex++;
                }
            }

            //fequency
            // tengo que recorrerlos 1 por 1 por que los tienen en un valor de array separado si uso insert.. tengo q borrar y insertar el nuevo
            ToUpdate.communicationPreference.frequencies = new Innovaction.CustomerDataWS.frequencyTo[rb_Frequency.Items.Count];
            int tmpFCount = 0;
            foreach (ListItem TheFrequency in rb_Frequency.Items)
            {
                var Frequency = new Innovaction.CustomerDataWS.frequencyTo();
                Frequency.id = TheFrequency.Value;
                if (TheFrequency.Selected)
                {
                    Frequency.operationType = Innovaction.CustomerDataWS.operationType.INSERT;
                }
                else
                {
                    Frequency.operationType = Innovaction.CustomerDataWS.operationType.DELETE;
                }
                Frequency.operationTypeSpecified = true;
                Frequency.active = true;


                ToUpdate.communicationPreference.frequencies[tmpFCount] = Frequency;
                tmpFCount++;
            }

            // channel
            // mismo caso que la frequency..

            ToUpdate.communicationPreference.channels = new Innovaction.CustomerDataWS.channelTo[rb_Channel.Items.Count];
            int tmpCounter = 0;
            foreach (ListItem TheChannel in rb_Channel.Items)
            {
                var Channel = new Innovaction.CustomerDataWS.channelTo();
                Channel.id = TheChannel.Value;
                if (TheChannel.Selected)
                {
                    Channel.operationType = Innovaction.CustomerDataWS.operationType.INSERT;
                }
                else
                {
                    Channel.operationType = Innovaction.CustomerDataWS.operationType.DELETE;
                }
                Channel.operationTypeSpecified = true;
                Channel.active = true;


                ToUpdate.communicationPreference.channels[tmpCounter] = Channel;
                tmpCounter++;
            }

            #endregion



            // we update the customer
            var respuesta = Innovaction.WSManager.UpdateCustomer(ToUpdate, ThePortalID);
            if (respuesta.responseCode == CustomerDataWS.responseCode.SUCCESS)
            {
                DnnAlert("Gracias! Sus datos han sido guardados exitosamente.", 300);
            }
            else
            {
                DnnAlert("Error al actualizar los datos: " + respuesta.responseMessage, 300);
            }

            // response output debugg.
        }