Exemple #1
0
        public async Task <IActionResult> AgregarNuevaFoto(
            IFormFile Files, PictureViewModels PictureViewModels)
        {
            string NombreImagenInicial = string.Empty;
            string NombreImagen        = string.Empty;

            if (Files.Name.Length >= 5)
            {
                if (Files.Name.Contains(".jpg") || Files.Name.Contains(".JPEG") || Files.Name.Contains(".gif") || Files.Name.Contains(".png") || Files.Name.Contains(".tif"))
                {
                    NombreImagenInicial = Files.Name.Replace(" ", "");


                    ///////

                    var Insert_Fotos = new PictureViewModels();

                    if (PictureViewModels != null)
                    {
                        var GetValue  = new BEFotos();
                        var GetValuep = new BEProducto();
                        GetValue.descripcion      = PictureViewModels.descripcionImagen;
                        GetValue.Nombre           = PictureViewModels.NombreImagen;
                        GetValue.posicionPortada  = PictureViewModels.posicionPortada;
                        GetValuep.Descripcion     = PictureViewModels.DescripcionProducto;
                        GetValuep.fechaexpiracion = PictureViewModels.fechaexpiracion;
                        GetValuep.fechaproduccion = PictureViewModels.fechaproduccion;
                        GetValuep.Nombre          = PictureViewModels.NombreProducto;
                        GetValuep.Precio          = PictureViewModels.Precio;
                        GetValuep.Stock           = PictureViewModels.Stock;
                        var Gui = new Guid();
                        NombreImagen = PictureViewModels.NombreImagen.Replace(" ", "") + Gui.ToString();

                        Insert_Fotos = _IFotos.Insert_BEFoto(GetValue, GetValuep);
                    }


                    // solo guarda si se completo el insert de las entidades
                    var PathToSave = Path.Combine(_IEnviroment.WebRootPath, "Imagen");
                    if (Files.Length > 0)
                    {
                        if (Insert_Fotos.CantidadDeregistros > 0)
                        {
                            using (var SaveFile = new FileStream(Path.Combine(PathToSave, NombreImagen + NombreImagenInicial), FileMode.Create))
                            {
                                await Files.CopyToAsync(SaveFile);
                            }
                        }
                    }
                }
            }

            /////////////////
            //var file = Request.;
            return(View());
        }
Exemple #2
0
        public bool ValidaFotoProducto(long idfoto, long idproducto)
        {
            Conecta Conecta   = new Conecta();
            string  Conexion  = Conecta.GetConexion().ConnectionString;
            BEFotos Foto      = new BEFotos();
            bool    Error     = false;
            string  Respuesta = string.Empty;

            try
            {
                var Parameter = new SqlParameter[4];
                Parameter[0] = new SqlParameter("@idfoto", SqlDbType.BigInt)
                {
                    Value = idfoto
                };
                Parameter[1] = new SqlParameter("@idproducto", SqlDbType.BigInt)
                {
                    Value = idproducto
                };
                Parameter[2] = new SqlParameter("@Error", SqlDbType.Bit)
                {
                    Direction = ParameterDirection.Output
                };
                Parameter[3] = new SqlParameter("@Respuesta", SqlDbType.NVarChar, 200)
                {
                    Direction = ParameterDirection.Output
                };

                using (var read = PI_Video_Imagen.Data.SqlHelper.ExecuteReader(Conexion, CommandType.StoredProcedure, "dbo.Validar_insert_Foto", Parameter))
                {
                    read.Read();
                    if (read.HasRows)
                    {
                        Error     = read.GetBoolean(read.GetOrdinal("Error"));
                        Respuesta = read.GetString(read.GetOrdinal("Respuesta"));
                        if (Error == true)
                        {
                            Error = true;
                        }
                    }
                }
            }

            catch (Exception ex)
            {
                throw ex;
            }

            return(Error);
        }
Exemple #3
0
        public BEFotos ListaImagen(string NombreImagen)
        {
            Conecta Conecta   = new Conecta();
            string  Conexion  = Conecta.GetConexion().ConnectionString;
            BEFotos Foto      = new BEFotos();
            bool    Error     = false;
            string  Respuesta = string.Empty;

            try
            {
                var Parameter = new SqlParameter[3];
                Parameter[0] = new SqlParameter("@Nombre", SqlDbType.VarChar)
                {
                    Value = NombreImagen.Trim()
                };
                Parameter[1] = new SqlParameter("@Error", SqlDbType.Bit)
                {
                    Direction = ParameterDirection.Output
                };
                Parameter[2] = new SqlParameter("@Respuesta", SqlDbType.NVarChar, 200)
                {
                    Direction = ParameterDirection.Output
                };

                using (var read = PI_Video_Imagen.Data.SqlHelper.ExecuteReader(Conexion, CommandType.StoredProcedure, "dbo.ListarRankingImagenesByName", Parameter))
                {
                    read.Read();
                    if (read.HasRows)
                    {
                        Foto.idfoto = read.GetInt64(read.GetOrdinal("idfoto"));
                        Foto.Nombre = read.GetString(read.GetOrdinal("Nombre"));
                        if (Foto.Nombre != null && Foto.idfoto != 0)
                        {
                            Foto.rutafoto = Conecta.GetFilePath() + Foto.Nombre.Trim();
                        }
                        Error     = read.GetBoolean(read.GetOrdinal("Error"));
                        Respuesta = read.GetString(read.GetOrdinal("Respuesta"));
                    }
                }
            }

            catch (Exception ex)
            {
                throw ex;
            }

            return(Foto);
        }
Exemple #4
0
        public IEnumerable <BEFotos> ListaImagen()
        {
            Conecta         Conecta   = new Conecta();
            string          Conexion  = Conecta.GetConexion().ConnectionString;
            Queue <BEFotos> ListaFoto = new Queue <BEFotos>();

            try
            {
                var Parameter = new SqlParameter[3];
                Parameter[0] = new SqlParameter("@idfoto", SqlDbType.Int)
                {
                    Value = 0
                };
                Parameter[1] = new SqlParameter("@Error", SqlDbType.Bit)
                {
                    Direction = ParameterDirection.Output
                };
                Parameter[2] = new SqlParameter("@Respuesta", SqlDbType.NVarChar, 200)
                {
                    Direction = ParameterDirection.Output
                };

                using (var read = PI_Video_Imagen.Data.SqlHelper.ExecuteReader(Conexion, CommandType.StoredProcedure, "dbo.ListarRankingImagenes", Parameter))
                {
                    while (read.Read() && read.HasRows && !read.IsDBNull(read.GetOrdinal("hashCode")))
                    {
                        BEFotos Imagenobj = new BEFotos();
                        Imagenobj.idfoto   = read.GetInt64(read.GetOrdinal("idfoto"));
                        Imagenobj.Nombre   = read.GetString(read.GetOrdinal("Nombre"));
                        Imagenobj.rutafoto = @"F:\Learn MVC\API_Video_Imagen\src\API_Video_Imagen\wwwroot\Imagen\in_vivo_izasascientific.jpg";
                        ListaFoto.Enqueue(Imagenobj);
                    }
                }
            }

            catch (Exception ex)
            {
                throw ex;
            }

            return(ListaFoto);
        }
Exemple #5
0
        public Queue <MPProducto> GetLisRutaProducto(int idFoto, string Conexion, string RutaFotos)
        {
            Queue <MPProducto> lstBEfotoProducto = new Queue <MPProducto>();


            try
            {
                var Parameter = new SqlParameter[4];
                Parameter[0] = new SqlParameter("@CallAPP", SqlDbType.VarChar)
                {
                    Value = "APP_Publicidad"
                };
                Parameter[1] = new SqlParameter("@idfoto", SqlDbType.Int)
                {
                    Value = idFoto
                };
                Parameter[2] = new SqlParameter("@Error", SqlDbType.Bit)
                {
                    Direction = ParameterDirection.Output
                };
                Parameter[3] = new SqlParameter("@Respuesta", SqlDbType.NVarChar, 200)
                {
                    Direction = ParameterDirection.Output
                };

                using (var read = SqlHelper.ExecuteReader(Conexion, CommandType.StoredProcedure, "dbo.ListarRankingImagenes", Parameter))
                {
                    while (read.Read() && read.HasRows && !read.IsDBNull(read.GetOrdinal("hashCode")))
                    {
                        //MPProducto BEfotoProducto = new MPProducto();
                        MPProducto MPObjeto = new MPProducto();
                        BEFotos    BEFoto   = new BEFotos();
                        BEProducto Producto = new BEProducto();

                        BEFoto.hashCode      = read.GetString(read.GetOrdinal("hashCode"));
                        BEFoto.idfoto        = read.GetInt64(read.GetOrdinal("idfoto"));
                        BEFoto.Nombre        = read.GetString(read.GetOrdinal("Nombre"));
                        Producto.codigo      = read.GetString(read.GetOrdinal("codigo"));
                        Producto.Descripcion = read.GetString(read.GetOrdinal("Descripcion"));
                        Producto.idproducto  = read.GetInt64(read.GetOrdinal("idproducto"));
                        Producto.Precio      = read.GetDecimal(read.GetOrdinal("Precio"));
                        Producto.idfoto      = read.GetInt64(read.GetOrdinal("idfoto"));
                        Producto.Nombre      = read.GetString(read.GetOrdinal("NombreProducto"));
                        BEFoto.rutafoto      = RutaFotos;
                        MPObjeto.BEFoto      = BEFoto;
                        MPObjeto.Producto    = Producto;
                        //BEfotoProducto.Error = false;
                        //BEfotoProducto.Respuesta = "OK";
                        lstBEfotoProducto.Enqueue(MPObjeto);
                    }
                    //else
                    //{

                    //    //read.NextResult();
                    //    error = read.GetBoolean(read.GetOrdinal("Error"));
                    //    respuesta = read.GetString(read.GetOrdinal("Respuesta"));

                    //}
                }
            }

            catch (Exception ex)
            {
                throw ex;
            }

            return(lstBEfotoProducto);
        }
        public PictureViewModels Insert_BEFoto(BEFotos BEImagen, BEProducto BEProducto)
        {
            PictureViewModels Cantidadregistros = new PictureViewModels();
            int cantidadregistro = 0;

            using (var conexion = new SqlConnection())
            {
                API_Video_Imagen.Data.Repository.Conecta Conecta = new API_Video_Imagen.Data.Repository.Conecta();
                string Conexion = Conecta.GetConexion().ConnectionString;

                try
                {
                    var Parameter = new SqlParameter[13];
                    Parameter[0] = new SqlParameter("@Nombre", SqlDbType.VarChar, 300)
                    {
                        Value = BEImagen.Nombre
                    };
                    Parameter[1] = new SqlParameter("@rutafoto", SqlDbType.VarChar, 300)
                    {
                        Value = ""
                    };
                    Parameter[2] = new SqlParameter("@posicionPortada", SqlDbType.Int)
                    {
                        Value = BEImagen.posicionPortada
                    };
                    Parameter[3] = new SqlParameter("@descripcion", SqlDbType.VarChar, 500)
                    {
                        Value = BEImagen.descripcion
                    };
                    Parameter[4] = new SqlParameter("@NombreProducto", SqlDbType.VarChar, 500)
                    {
                        Value = BEProducto.Nombre
                    };
                    Parameter[5] = new SqlParameter("@DescripcionProducto", SqlDbType.VarChar, 600)
                    {
                        Value = BEProducto.Descripcion
                    };
                    Parameter[6] = new SqlParameter("@Precio", SqlDbType.Decimal)
                    {
                        Value = BEProducto.Precio
                    };
                    Parameter[7] = new SqlParameter("@Stock", SqlDbType.Int)
                    {
                        Value = BEProducto.Stock
                    };
                    Parameter[8] = new SqlParameter("@fechaproduccion", SqlDbType.DateTime)
                    {
                        Value = BEProducto.fechaproduccion
                    };
                    Parameter[9] = new SqlParameter("@fechaexpiracion", SqlDbType.DateTime)
                    {
                        Value = BEProducto.fechaexpiracion
                    };
                    Parameter[10] = new SqlParameter("@Error", SqlDbType.Bit)
                    {
                        Direction = ParameterDirection.Output
                    };
                    Parameter[11] = new SqlParameter("@Respuesta", SqlDbType.NVarChar, 200)
                    {
                        Direction = ParameterDirection.Output
                    };
                    Parameter[12] = new SqlParameter("@CantidadRegistrado ", SqlDbType.Int)
                    {
                        Direction = ParameterDirection.Output
                    };
                    using (var read = PI_Video_Imagen.Data.SqlHelper.ExecuteReader(Conexion, CommandType.StoredProcedure, "dbo.Insert_Foto", Parameter))
                    {
                        while (read.Read())
                        {
                            Cantidadregistros.idfoto = Int64.Parse(read.GetInt64(read.GetOrdinal("IdFoto")).ToString());
                            Cantidadregistros.CantidadDeregistros = Int32.Parse(read.GetInt32(read.GetOrdinal("CantidadRegistrado")).ToString());
                            Cantidadregistros.idproducto          = Int64.Parse(read.GetInt64(read.GetOrdinal("IdFoto")).ToString());
                        }
                    }
                }

                catch (Exception ex)
                {
                    throw ex;
                }
            }

            return(Cantidadregistros);
        }