コード例 #1
0
        public ActionResult Upload(TiendaVirtualDTO tienda, HttpPostedFileBase image)
        {
            TiendaVirtualDTO tiendaDTO = _bl.ObtenerTienda(tienda.TiendaVitualId);

            if (image.ContentLength < 2097152)
            {
                var nombreFoto = tienda.Dominio + Guid.NewGuid().ToString() + "_portada";
                CloudBlobContainer blobContainer = _bss.GetContainerTienda(tienda.Dominio);
                CloudBlockBlob     blob          = blobContainer.GetBlockBlobReference(nombreFoto);

                ImagenesDTO imagen = new ImagenesDTO();
                imagen.TiendaId         = tiendaDTO.TiendaVitualId;
                imagen.Nombre           = nombreFoto;
                imagen.UrlImagenMediana = blob.Uri.ToString();
                _bl.AgregarImagenTienda(imagen);


                blob.UploadFromStream(image.InputStream);

                return(RedirectToAction("Upload", "TiendaVirtual", new { id = tiendaDTO.TiendaVitualId, mensaje = "Se agrego la imagen correctamente", tipo = "success" }));
            }
            else
            {
                return(RedirectToAction("Upload", "TiendaVirtual", new { id = tiendaDTO.TiendaVitualId, mensaje = "Tamaño maximo 2 MB", tipo = "warning" }));
            }
        }
コード例 #2
0
        public void AgregarImagenTienda(ImagenesDTO img)
        {
            try
            {   //var tienda = Mapper.Map<TiendaVirtual>(tiendaDTO);
                //tiendaDTO.ListaImagenes = Mapper.Map<ICollection<Imagenes>>(tiendaDTO.ListaImagenes);

                db.Imagenes.Add(img);
                db.SaveChanges();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #3
0
ファイル: ProductosDatos.cs プロジェクト: LoganFenix/Gastos
        public List <ProductosDTO> ListaProductos()
        {
            using (ControlPersonalEntities2 contexto = new ControlPersonalEntities2())
            {
                var listaproductos = new List <ProductosDTO>();

                var productos =
                    (from x in contexto.Productos


                     select x).OrderBy(x => x.IdProducto).ToList();


                foreach (var producto in productos)
                {
                    ProductosDTO lista = new ProductosDTO();

                    lista.IdProducto      = producto.IdProducto;
                    lista.NombreTipoGasto = producto.TiposdeGastos.DescripcionGasto;
                    lista.Nombre          = producto.Nombre;

                    List <ImagenesDTO> ListallenaImagenes = new List <ImagenesDTO>();

                    if (contexto.Imagenes.Where(x => x.IdProducto == producto.IdProducto).Count() > 0)
                    {
                        var imagenes = contexto.Imagenes.Where(x => x.IdProducto == producto.IdProducto).ToList();


                        foreach (Imagenes imagen in imagenes)
                        {
                            ImagenesDTO datos = new ImagenesDTO();

                            datos.Esportada      = imagen.Esportada.HasValue? imagen.Esportada.Value:false;
                            datos.IdImagen       = imagen.IdImagen;
                            datos.IdProducto     = imagen.IdProducto;
                            datos.UrlImagenChica = imagen.UrlImagenChica;
                            ListallenaImagenes.Add(datos);
                        }
                    }

                    lista.ListaImagenes = ListallenaImagenes;
                    listaproductos.Add(lista);
                }



                return(listaproductos);
            }
        }
コード例 #4
0
ファイル: ProductosDatos.cs プロジェクト: LoganFenix/Gastos
        public ProductosDTO ObtenerProducto(Guid IdProducto)
        {
            using (ControlPersonalEntities2 contexto = new ControlPersonalEntities2())
            {
                var producto                = contexto.Productos.FirstOrDefault(x => x.IdProducto == IdProducto);
                var listaimagenes           = contexto.Imagenes.Where(x => x.IdProducto == IdProducto).ToList();
                List <ImagenesDTO> imagenes = new List <ImagenesDTO>();

                if (listaimagenes != null)
                {
                    foreach (Imagenes imagen in listaimagenes)
                    {
                        ImagenesDTO datos = new ImagenesDTO();
                        datos.IdImagen        = imagen.IdImagen;
                        datos.IdProducto      = imagen.IdProducto;
                        datos.Esportada       = imagen.Esportada.Value;
                        datos.UrlImagenChica  = imagen.UrlImagenChica;
                        datos.UrlImagenGrande = imagen.UrlImagenGrande;

                        imagenes.Add(datos);
                    }
                }



                if (producto != null)
                {
                    return(new ProductosDTO()
                    {
                        IdProducto = producto.IdProducto,
                        IdTipoGasto = producto.IdTipoGasto,
                        Nombre = producto.Nombre,
                        NombreTipoGasto = producto.TiposdeGastos.DescripcionGasto,
                        Descripcion = producto.Descripcion,
                        Video = producto.Video,


                        ListaImagenes = imagenes,
                    });
                }
                else
                {
                    return(new ProductosDTO());
                }
            }
        }
コード例 #5
0
 public void AgregarImagenTienda(ImagenesDTO img)
 {
     _dal.AgregarImagenTienda(img);
 }
コード例 #6
0
ファイル: ProductosDatos.cs プロジェクト: LoganFenix/Gastos
        public void ActualizarProducto(ProductosDTO ActualizarProducto)
        {
            using (ControlPersonalEntities2 contexto = new ControlPersonalEntities2())
            {
                if (ActualizarProducto.ListaImagenes != null && ActualizarProducto.ListaImagenes.Any())
                {
                    foreach (var imagen in ActualizarProducto.ListaImagenes)
                    {
                        string fileName = Guid.NewGuid().ToString();

                        if (!imagen.ImagenEliminada && imagen.ImagenSubida != null)
                        {
                            imagen.UrlImagenChica  = new GuardarImagen().ResizeAndSave(fileName, imagen.ImagenSubida.InputStream, Tamanos.Miniatura, false);
                            imagen.UrlImagenGrande = new GuardarImagen().ResizeAndSave(fileName, imagen.ImagenSubida.InputStream, Tamanos.Mediana, false);


                            ActualizarProducto.ListaImagenes.ToList().Add(new ImagenesDTO()
                            {
                                UrlImagenChica  = imagen.UrlImagenChica,
                                UrlImagenGrande = imagen.UrlImagenGrande
                            });
                        }
                    }
                }


                var producto = contexto.Productos.FirstOrDefault(x => x.IdProducto == ActualizarProducto.IdProducto);

                if (producto != null)
                {
                    producto.IdTipoGasto = ActualizarProducto.IdTipoGasto;
                    producto.Nombre      = ActualizarProducto.Nombre;
                    producto.Video       = ActualizarProducto.Video;



                    if (ActualizarProducto.ListaImagenes != null)
                    {
                        List <ImagenesDTO> imagenesagregar = new List <ImagenesDTO>();



                        foreach (var imagen in ActualizarProducto.ListaImagenes)
                        {
                            var imagenes = contexto.Imagenes.Any(x => x.IdImagen == imagen.IdImagen);
                            if (imagenes == false)
                            {
                                Imagenes datos = new Imagenes();
                                datos.IdImagen        = Guid.NewGuid();
                                datos.IdProducto      = producto.IdProducto;
                                datos.Esportada       = imagen.Esportada;
                                datos.UrlImagenChica  = imagen.UrlImagenChica;
                                datos.UrlImagenGrande = imagen.UrlImagenGrande;
                                datos.UsuarioAlta     = "";
                                datos.FechaAlta       = DateTime.Now;

                                contexto.Imagenes.Add(datos);
                                contexto.SaveChanges();


                                ImagenesDTO datosimagen = new ImagenesDTO();

                                datosimagen.IdImagen   = datos.IdImagen;
                                datosimagen.IdProducto = datos.IdProducto;
                                imagenesagregar.Add(datosimagen);
                            }

                            else
                            {
                                var imagenediatada = contexto.Imagenes.FirstOrDefault(x => x.IdImagen == imagen.IdImagen);

                                imagenediatada.Esportada       = imagen.Esportada;
                                imagenediatada.UrlImagenChica  = imagen.UrlImagenChica;
                                imagenediatada.UrlImagenGrande = imagen.UrlImagenGrande;


                                contexto.SaveChanges();



                                ImagenesDTO datosimagen = new ImagenesDTO();

                                datosimagen.IdImagen   = imagenediatada.IdImagen;
                                datosimagen.IdProducto = imagenediatada.IdProducto;
                                imagenesagregar.Add(datosimagen);
                            }
                        }



                        Guid[] numimag           = imagenesagregar.Select(x => x.IdImagen).ToArray();
                        var    imagenesaeliminar = contexto.Imagenes.Where(x => !numimag.Contains(x.IdImagen) && x.IdProducto == producto.IdProducto).ToList();


                        foreach (var imagen in imagenesaeliminar)
                        {
                            var eliminarImagen = contexto.Imagenes.FirstOrDefault(r => r.IdImagen == imagen.IdImagen && imagen.IdProducto == imagen.IdProducto);
                            if (eliminarImagen != null)
                            {
                                contexto.Imagenes.Remove(eliminarImagen);
                            }
                        }
                    }

                    else
                    {
                        if (contexto.Imagenes.Where(x => x.IdProducto == producto.IdProducto).Count() > 0)
                        {
                            var imagenesaeliminar = contexto.Imagenes.Where(x => x.IdProducto == producto.IdProducto).ToList();


                            foreach (var imagen in imagenesaeliminar)
                            {
                                var eliminarImagen = contexto.Imagenes.FirstOrDefault(r => r.IdImagen == imagen.IdImagen);
                                if (eliminarImagen != null)
                                {
                                    contexto.Imagenes.Remove(eliminarImagen);
                                }
                            }
                        }
                    }



                    contexto.SaveChanges();
                }
            }
        }