Exemplo n.º 1
0
        public async Task <ActionResult> POST([FromBody] ImagenViewModel product)
        {
            if (ModelState.IsValid)
            {
                _context.Products.Add(product);
                _context.SaveChanges();
                var path = string.Empty;

                if (product.ImageFile != null && product.ImageFile.Length > 0)
                {
                    path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot\\images\\Products", product.ImageFile.FileName);

                    using (var stream = new FileStream(path, FileMode.Create))
                    {
                        await product.ImageFile.CopyToAsync(stream);
                    }

                    path = $"~/images/Products/{product.ImageFile.FileName}";
                }

                var vProduct = this.ToProduct(product, path);
                return(new CreatedAtRouteResult("creado", new { id = product.Id }));
            }
            return(BadRequest(ModelState));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Crear([FromBody] ImagenViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Imagenes imagen = new Imagenes
            {
                nombre = model.nombre,
                imagen = model.imagen
            };

            _context.Imagenes.Add(imagen);
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                return(BadRequest(ex));
            }

            return(Ok());
        }
Exemplo n.º 3
0
        public PartialViewResult GetFotoPorId(int idFoto)
        {
            int ClienteId = GetClienteSeleccionado();

            if (ClienteId == 0)
            {
                return(null);
            }

            Imagen img = imagenesRepository.GetFotoPorId(ClienteId, idFoto);

            ImagenViewModel model = new ImagenViewModel()
            {
                id                    = img.id,
                comentarios           = img.comentarios,
                cantTags              = img.cantTags,
                fechaCreacion         = img.fechaCreacion,
                idPuntoDeVenta        = img.idPuntoDeVenta,
                idReporte             = img.idReporte,
                imgb64                = img.imgb64,
                nombrePuntoDeVenta    = img.nombrePuntoDeVenta,
                tags                  = img.tags,
                direccionPuntoDeVenta = img.direccion,
                provincia             = img.provincia,
                Usuario               = img.usuario
            };

            return(PartialView("_imagenPreview", model));
        }
Exemplo n.º 4
0
        public IActionResult Imagen(ImagenViewModel vm)
        {
            try
            {
                if (vm.Archivo == null)
                {
                    ModelState.AddModelError("", "Debe seleccionar la imagen de la especie.");
                    return(View(vm));
                }
                else
                {
                    if (vm.Archivo.ContentType != "image/jpeg" || vm.Archivo.Length > 1024 * 1024 * 2)
                    {
                        ModelState.AddModelError("", "Debe seleccionar un archivo jpg maximo de 2MB.");
                        return(View(vm));
                    }
                }
                if (vm.Archivo != null)
                {
                    FileStream fs = new FileStream(Enviroment.WebRootPath + "/especies/" + vm.Especies.Id + ".jpg", FileMode.Create);
                    vm.Archivo.CopyTo(fs);
                    fs.Close();
                }

                return(RedirectToAction("Index", "Home"));
            }
            catch (Exception error)
            {
                ModelState.AddModelError("", error.Message);
                return(View(vm));
            }
        }
Exemplo n.º 5
0
        public PropiedadViewModel ToViewModel(PROPIEDAD propiedad)
        {
            this.IdPropiedad = propiedad.IdPropiedad;
            this.Nombre      = propiedad.Nombre;
            this.Descripcion = propiedad.Descripcion;
            this.Pais        = propiedad.Pais;
            this.Ciudad      = propiedad.Ciudad;
            this.Activa      = propiedad.Activa;

            this.Imagenes = new List <ImagenViewModel>();

            foreach (var imagen in propiedad.IMAGEN)
            {
                this.Imagenes.Add(new ImagenViewModel().ToViewModel(imagen));
            }

            if (!this.Imagenes.Any())
            {
                var imagenDefault = new ImagenViewModel();
                imagenDefault.path = "/app-content/noimage_residencia.png";

                this.Imagenes.Add(imagenDefault);
            }

            return(this);
        }
Exemplo n.º 6
0
 private Product ToProduct(ImagenViewModel product, string path)
 {
     return(new Product
     {
         Id = product.Id,
         Name = product.Name,
         Description = product.Description,
         IsAvalible = product.IsAvalible,
         Price = product.Price,
         Image = path
     });
 }
Exemplo n.º 7
0
        public IActionResult Imagen(int id)
        {
            animalesContext    context = new animalesContext();
            EspeciesRepository repos   = new EspeciesRepository(context);
            ImagenViewModel    vm      = new ImagenViewModel();

            vm.Especies = repos.GetById(id);
            if (System.IO.File.Exists(Enviroment.WebRootPath + $"/especies/{vm.Especies.Id}.jpg"))
            {
                vm.Imagen = vm.Especies.Id + ".jpg";
            }
            else
            {
                vm.Imagen = "SinFoto.jpg";
            }
            return(View(vm));
        }