Esempio n. 1
0
        // const string strcnn = @"Data Source=82.223.108.84,10606;Initial Catalog=btcDB; User ID=sa;Password=Carloselias23.; Packet Size=4096";
        //const string strcnn = @"Data Source=localhost;Initial Catalog=gamekeyspotdb;User ID=sa;Password=Carloselias23.;Packet Size=4096";

        public async Task <Dictionary <string, object> > xxAsync(ProductosModel model)
        {
            Dictionary <string, object> d = new Dictionary <string, object>();

            string sql = "select * from alojamientos";

            var xx = await FuncionesSQL.GetData(sql, null);

            List <SqlParameter> s = new List <SqlParameter>();

            return(d);
        }
Esempio n. 2
0
        public static Dictionary <string, object> AgregarProducto(ProductosModel model)
        {
            Dictionary <string, object> d = new Dictionary <string, object>();

            FuncionesSQL.ConeccionString = strcnn;

            string sqlExiste = "select count(*) from tblproductos where id_codewhosale = @id_codewhosale and escodewhosale = 1";

            List <SqlParameter> s = new List <SqlParameter>();

            s.Add(new SqlParameter()
            {
                ParameterName = "@ProductosNombre",
                Value         = model.productName,
                DbType        = DbType.String,
                SqlValue      = model.productName
            });

            s.Add(new SqlParameter()
            {
                ParameterName = "@id_codewhosale",
                Value         = model.productCodewhosaleId,
                DbType        = DbType.String,
                SqlValue      = model.productCodewhosaleId
            });

            var resultExiste = FuncionesSQL.PostData(sqlExiste, s, 1).Result;

            if (resultExiste.ContainsKey("error"))
            {
                d.Add("error", resultExiste.ContainsKey("error"));

                return(d);
            }

            if (Convert.ToInt32(resultExiste["valor"]) < 1)
            {
                Console.WriteLine("resultExiste: " + resultExiste["valor"]);

                string sqlbuscaCategoriaId = "select * from tblproductoscategorias where lower(CategoriasNombre) = lower(@CategoriasNombre)";

                List <SqlParameter> sc = new List <SqlParameter>();

                sc.Add(new SqlParameter()
                {
                    ParameterName = "@CategoriasNombre",
                    Value         = model.categoriaNombre,
                    DbType        = DbType.String,
                    SqlValue      = model.categoriaNombre
                });

                Console.WriteLine("categoriaNombre: " + model.categoriaNombre + "_" + sqlbuscaCategoriaId);

                var resultsqlbuscaCategoriaId = FuncionesSQL.GetData(sqlbuscaCategoriaId, sc).Result;


                Console.WriteLine("*********************");


                if (resultsqlbuscaCategoriaId.ContainsKey("error"))
                {
                    Console.WriteLine("error: " + resultsqlbuscaCategoriaId["error"]);
                    Console.WriteLine("*********************");
                }

                string categoria   = string.Empty;
                string categoriaId = string.Empty;

                if (resultsqlbuscaCategoriaId.ContainsKey("valor"))
                {
                    try
                    {
                        var dcategoria = resultsqlbuscaCategoriaId["valor"];
                        if (dcategoria != null)
                        {
                            DataRow dr = (DataRow)resultsqlbuscaCategoriaId["p_valor"];

                            Console.WriteLine("p_valor: " + dr["CategoriasNombre"]);

                            categoria   = dr["CategoriasNombre"].ToString();
                            categoriaId = dr["CategoriasId"].ToString();

                            Console.WriteLine("* ********************");
                        }
                        else
                        {
                            Console.WriteLine("datos nulos * ********************");
                        }
                    }
                    catch (Exception ex)
                    {
                        categoria   = "";
                        categoriaId = "0";

                        Console.WriteLine("No contiene error :" + ex.Message + "*********************");
                    }
                }
                ;


                Console.WriteLine("Entro en resultsqlbuscaCategoriaId: " + categoria + " - " + categoriaId);

                if (Convert.ToInt32(categoriaId) > 0)
                {
                    Console.WriteLine("Entro en tblproductos: " + model);

                    string sqlInsert = "INSERT INTO tblproductos(CategoriasId, ProductosFechaCreacion," +
                                       "ProductosNombre," +
                                       "ProductosCodigo," +
                                       "ProductosImagen," +
                                       "ProductosDescripcion," +
                                       "ProductosDescripcionAmpliada," +
                                       "ProductosPrecio," +
                                       "ProductosPrecioVenta," +
                                       "ProductosCantidad," +
                                       "Visible," +
                                       "regions,lenguajes," +
                                       "escodewhosale," +
                                       "id_codewhosale," +
                                       "officialTitle," +
                                       "category, developerName, developerHomepage" +
                                       ")" +
                                       "VALUES" +
                                       "(@CategoriasId, GETDATE()," +
                                       "@ProductosNombre," +
                                       "@ProductosCodigo," +
                                       "@ProductosImagen," +
                                       "@ProductosDescripcion," +
                                       "@ProductosDescripcionAmpliada," +
                                       "@ProductosPrecio," +
                                       "@ProductosPrecioVenta," +
                                       "@ProductosCantidad," +
                                       "@Visible,@regions," +
                                       "@lenguajes," +
                                       "@escodewhosale," +
                                       "@id_codewhosale," +
                                       "@officialTitle," +
                                       "@category, @developerName, @developerHomepage); SELECT CAST(scope_identity() AS int)";

                    List <SqlParameter> sInsert = new List <SqlParameter>();

                    sInsert.Add(new SqlParameter()
                    {
                        ParameterName = "CategoriasId",
                        Value         = Convert.ToInt32(categoriaId),
                        DbType        = DbType.Int32,
                        SqlValue      = Convert.ToInt32(categoriaId),
                        SqlDbType     = SqlDbType.Int
                    });

                    sInsert.Add(new SqlParameter()
                    {
                        ParameterName = "@ProductosNombre",
                        SqlValue      = model.productName,
                        Value         = model.productName,
                        DbType        = DbType.String,
                        SqlDbType     = SqlDbType.VarChar
                    });


                    sInsert.Add(new SqlParameter()
                    {
                        ParameterName = "@ProductosCodigo",
                        SqlValue      = model.identifier,
                        Value         = model.identifier,
                        DbType        = DbType.String,
                        SqlDbType     = SqlDbType.VarChar
                    });

                    sInsert.Add(new SqlParameter()
                    {
                        ParameterName = "@ProductosImagen",
                        SqlValue      = model.images,
                        Value         = model.images,
                        DbType        = DbType.String
                    });

                    Console.WriteLine("sInsert: parametros 1 - 4");

                    sInsert.Add(new SqlParameter()
                    {
                        ParameterName = "@ProductosDescripcion",
                        SqlValue      = model.description,
                        Value         = model.description,
                        DbType        = DbType.String
                    });

                    sInsert.Add(new SqlParameter()
                    {
                        ParameterName = "@ProductosDescripcionAmpliada",
                        SqlValue      = model.description,
                        Value         = model.description,
                        DbType        = DbType.String
                    });

                    sInsert.Add(new SqlParameter()
                    {
                        ParameterName = "@ProductosPrecio",
                        SqlValue      = model.prices,
                        Value         = model.prices,
                        DbType        = DbType.Decimal
                    });

                    decimal porcentaje = Convert.ToDecimal(.20);

                    sInsert.Add(new SqlParameter()
                    {
                        ParameterName = "@ProductosPrecioVenta",
                        SqlValue      = model.prices + ((model.prices * porcentaje) / 100),
                        Value         = model.prices + ((model.prices * porcentaje) / 100),
                        DbType        = DbType.Decimal
                    });
                    Console.WriteLine("sInsert: parametros 4 - 8");
                    sInsert.Add(new SqlParameter()
                    {
                        ParameterName = "@ProductosCantidad",
                        SqlValue      = model.quantity,
                        Value         = model.quantity,
                        DbType        = DbType.String
                    });

                    sInsert.Add(new SqlParameter()
                    {
                        ParameterName = "@Visible",
                        SqlValue      = true,
                        Value         = true,
                        DbType        = DbType.Boolean
                    });

                    sInsert.Add(new SqlParameter()
                    {
                        ParameterName = "@regions",
                        SqlValue      = model.regions,
                        Value         = model.regions,
                        DbType        = DbType.String,
                        SqlDbType     = SqlDbType.NVarChar
                    });

                    sInsert.Add(new SqlParameter()
                    {
                        ParameterName = "@lenguajes",
                        SqlValue      = model.languages,
                        Value         = model.languages,
                        DbType        = DbType.String
                    });
                    Console.WriteLine("sInsert: parametros 8 - 12");
                    //sInsert.Add(new SqlParameter()
                    //{
                    //    ParameterName = "@releaseDate",
                    //    SqlValue = model.releaseDate,
                    //    Value = model.releaseDate,
                    //    DbType = DbType.Date
                    //});

                    sInsert.Add(new SqlParameter()
                    {
                        ParameterName = "@escodewhosale",
                        SqlValue      = true,
                        Value         = true,
                        DbType        = DbType.Boolean
                    });

                    sInsert.Add(new SqlParameter()
                    {
                        ParameterName = "@id_codewhosale",
                        SqlValue      = model.productCodewhosaleId,
                        Value         = model.productCodewhosaleId,
                        DbType        = DbType.String
                    });

                    sInsert.Add(new SqlParameter()
                    {
                        ParameterName = "@officialTitle",
                        SqlValue      = model.officialTitle,
                        Value         = model.officialTitle,
                        DbType        = DbType.String
                    });

                    sInsert.Add(new SqlParameter()
                    {
                        ParameterName = "@category",
                        SqlValue      = model.category,
                        Value         = model.category,
                        DbType        = DbType.String
                    });

                    sInsert.Add(new SqlParameter()
                    {
                        ParameterName = "@developerName",
                        SqlValue      = model.developerName,
                        Value         = model.developerName,
                        DbType        = DbType.String
                    });

                    sInsert.Add(new SqlParameter()
                    {
                        ParameterName = "@developerHomepage",
                        SqlValue      = model.developerHomepage,
                        Value         = model.developerHomepage,
                        DbType        = DbType.String,
                        SqlDbType     = SqlDbType.NVarChar
                    });

                    Console.WriteLine("sInsert: parametros 8 - 12");

                    var r = FuncionesSQL.PostData(sqlInsert, sInsert, 1).Result;

                    Console.WriteLine("PostData: ");

                    if (r.ContainsKey("valor"))
                    {
                        d.Add("valor", r["valor"]);
                    }
                    else
                    {
                        dynamic e = r["error"];
                        Console.WriteLine("PostData: " + e);
                        d.Add("valor", e);
                    }

                    return(d);
                }
                else
                {
                    d.Add("error", "No existe categoria: " + model.categoriaNombre);

                    return(d);
                    ///errorr productos sin categoria//
                };
            }
            else
            {
                //edito producto//
                string sqlbuscadatosProducto = "select * from tblproductoscategorias where productoId = @productoId or  id_codewhosale = @id_codewhosale";

                List <SqlParameter> p_buscaProducto = new List <SqlParameter>();

                p_buscaProducto.Add(new SqlParameter()
                {
                    ParameterName = "@productoId",
                    Value         = model.productId,
                    DbType        = DbType.Int32,
                    SqlValue      = model.productId
                });

                p_buscaProducto.Add(new SqlParameter()
                {
                    ParameterName = "@id_codewhosale",
                    SqlValue      = model.productCodewhosaleId,
                    Value         = model.productCodewhosaleId,
                    DbType        = DbType.String
                });

                var resultsqlbuscaCategoriaId = FuncionesSQL.GetData(sqlbuscadatosProducto, p_buscaProducto).Result;
            };

            return(d);
        }