Beispiel #1
0
        public bool EnviarAPromociones(Promociones promo)
        {
            try
            {
                string URL = ConfigurationManager.AppSettings["URLPromo"];

                HttpClient client = new HttpClient();
                var        data   = new StringContent(JsonConvert.SerializeObject(promo), Encoding.UTF8, "application/json");

                // List data response.
                HttpResponseMessage response = client.PostAsync(URL, data).Result;

                if (response.IsSuccessStatusCode)
                {
                    return(true);
                }
                else
                {
                    using (IBaseDatos baseDatos = BaseDatos.Construir(new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["STR-CNN-LOYALTY"])))
                    {
                        string[] param = new string[] { "Mensaje" };
                        object[] value = new object[1];
                        value[0] = "RETRY: servicio de PROMOCIONES retorno Status code = " + response.StatusCode + " con el siguiente mensaje = " + response.RequestMessage.Content;

                        baseDatos.EjecutarSP("[LOYALTY].[sp_Logs_Insert]", param, value);
                    };
                    return(false);
                }
            }
            catch (Exception e) {
                using (IBaseDatos baseDatos = BaseDatos.Construir(new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["STR-CNN-LOYALTY"])))
                {
                    string[] param = new string[] { "Mensaje" };
                    object[] value = new object[1];
                    value[0] = "ERROR: servicio de Promociones no accesible, = " + e.Message;

                    baseDatos.EjecutarSP("[LOYALTY].[sp_Logs_Insert]", param, value);
                };
                return(false);
            }
        }
Beispiel #2
0
        protected void btnSend_Click(object sender, EventArgs e)
        {
            string[] param = new string[] { "DNI", "Apellido", "Nombre", "Genero", "FechaNacimiento", "Telefono", "Celular", "Direccion", "Postal", "Provincia", "ProvinciaNombre", "Ciudad", "CiudadNombre", "Email", "Grupo", "Tarjeta", "HashValidacion", "Enviado", "Validado" };
            object[] value = new object[19];
            value[0] = this.hfDNI.Value.ToString();
            value[1] = this.hfApellido.Value.ToString();
            value[2] = this.hfNombre.Value.ToString();
            value[3] = this.hfGenero.Value.ToString();

            DateTime dtFecha = DateTime.ParseExact(this.hfFechaNacimiento.Value.ToString(), "yyyy-MM-d", CultureInfo.InvariantCulture);
            string   fecha   = dtFecha.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture);

            value[4] = dtFecha;

            value[5] = this.hfTelefono.Value.ToString();
            value[6] = this.hfCelular.Value.ToString();
            value[7] = this.hfDireccion.Value.ToString();
            value[8] = this.hfPostal.Value.ToString();
            if (this.hfProvincia.Value.ToString().ToUpper() == ("Seleccione una provincia").ToUpper())
            {
                value[9]  = "0";
                value[10] = "";
            }
            else
            {
                value[9]  = this.hfProvincia.Value.ToString();
                value[10] = this.hfProvinciaNombre.Value.ToString();
            }
            if (this.hfCiudad.Value.ToString().ToUpper() == ("Seleccione una ciudad").ToUpper())
            {
                value[11] = "0";
                value[12] = "";
            }
            else
            {
                value[11] = this.hfCiudad.Value.ToString();
                value[12] = this.hfCiudadNombre.Value.ToString();
            }

            value[13] = this.hfEmail.Value.ToString();
            value[14] = this.hfGrupo.Value.ToString();
            value[15] = this.hfTarjeta.Value.ToString();
            value[16] = Helper.EncodeString(this.hfDNI.Value.ToString());
            value[17] = 0;
            value[18] = 0;
            value[19] = this.hfValidado.Value.ToString();

            /*****************
            * Envio de mail *
            * ***************/

            Email email = new Email();

            email.NombreRemitente = value[1].ToString() + " " + value[2].ToString();
            email.AsuntoMail      = ConfigurationManager.AppSettings["AsuntoEmail"];
            string cuerpoMail = Mail.CrearCuerpoMailValidacion(Server.UrlEncode(Helper.EncodeString(hfDNI.Value.ToString())),
                                                               value[2] + " " + value[1],
                                                               urlValidacion: ConfigurationManager.AppSettings["UrlValidacionMail"]);

            email.CuerpoMail   = cuerpoMail;
            email.Destinatario = value[13].ToString();
            email.IsBodyHtml   = ConfigurationManager.AppSettings["isBodyHtmlEmail"].Equals("True");

            /************************
            * Enviar datos a PROMO *
            * **********************/

            Promociones promo = new Promociones();

            promo.Catalog            = "CatalogCardAssign";
            promo.CompanyId          = "diarco";
            promo.CardId             = value[15].ToString();
            promo.CardTye            = value[15].ToString().Substring(value[15].ToString().Length - 4);
            promo.Contract           = value[14].ToString();
            promo.CustomerId         = value[0].ToString();
            promo.NombreCliente      = value[2].ToString();
            promo.ApellidoCliente    = value[1].ToString();
            promo.TipoIdentificacion = "DNI";
            promo.Identificacion     = value[0].ToString();
            promo.Amount             = 0.0D;


            if (ConfigurationManager.AppSettings["EmailEnable"].Equals("True"))
            {
                if (EnviarMailActivacion(email))
                {
                    value[17] = 1;
                }
            }
            else
            {
                using (IBaseDatos baseDatos = BaseDatos.Construir(new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["STR-CNN-LOYALTY"])))
                {
                    param    = new string[] { "Mensaje" };
                    value    = new object[1];
                    value[0] = "WARNING: servicio de Envio de MAIL inhabilitado por el Administrador";

                    baseDatos.EjecutarSP("[LOYALTY].[sp_Logs_Insert]", param, value);
                };
            }

            DataTable resultado = new DataTable();

            try
            {
                using (IBaseDatos baseDatos = BaseDatos.Construir(new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["STR-CNN-LOYALTY"])))
                {
                    baseDatos.EjecutarSP(resultado, "[LOYALTY].[sp_Clientes_Insert]", param, value);

                    foreach (DataRow item in resultado.Rows)
                    {
                        if (item[0].ToString() == "SI")
                        {
                            hfOperacion.Value = "ok";
                            if (ConfigurationManager.AppSettings["PromoEnable"].Equals("True"))
                            {
                                EnviarAPromociones(promo);
                            }
                            else
                            {
                                param    = new string[] { "Mensaje" };
                                value    = new object[1];
                                value[0] = "WARNING: servicio de PROMOCIONES inhabilitado por el Administrador";

                                baseDatos.EjecutarSP("[LOYALTY].[sp_Logs_Insert]", param, value);
                            }
                        }
                        else
                        {
                            lblError.Text     = item[1].ToString();
                            hfOperacion.Value = "error";
                        }
                    }
                }



                lblMensajeFinRegistracion.Text = "Muchas Gracias por Registrarte, recibirás un mensaje en " + value[13].ToString() + " con las instrucciones para activar tu tarjeta.";

                Session["InformacionRegistrada"] = true;

                return;
            }
            catch (Exception ex)
            {
                lblError.Text     = "Ha ocurrido un error, contacte al administrador del sistema.";
                hfOperacion.Value = "error";
                using (IBaseDatos baseDatos = BaseDatos.Construir(new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["STR-CNN-LOYALTY"])))
                {
                    param    = new string[] { "Mensaje" };
                    value    = new object[1];
                    value[0] = "ERROR: A ocurrido el siguiente error en proceso de insercion = " + ex.Message;

                    baseDatos.EjecutarSP("[LOYALTY].[sp_Logs_Insert]", param, value);
                };
                return;
            }
        }