public IActionResult Imagen(AdminCelularesViewModel 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 + "/CatalogoS/" + vm.Smartphones.Id + ".jpg", FileMode.Create); vm.Archivo.CopyTo(fs); fs.Close(); } return(RedirectToAction("Index", "Home")); } catch (Exception error) { ModelState.AddModelError("", error.Message); return(View(vm)); } }
public IActionResult Agregar() { AdminCelularesViewModel vm = new AdminCelularesViewModel(); Repository repository = new Repository(); vm.Marcas = repository.GetMarca(); return(View(vm)); }
public IActionResult Editar(uint id) { AdminCelularesViewModel vm = new AdminCelularesViewModel(); Repository repository = new Repository(); vm.Marcas = repository.GetMarca(); vm.Smartphones = repository.GetCelById(id); if (vm.Smartphones == null) { return(RedirectToAction("Index")); } return(View(vm)); }
public IActionResult Imagen(uint id) { celularesContext context = new celularesContext(); Repository repos = new Repository(); AdminCelularesViewModel vm = new AdminCelularesViewModel(); vm.Marcas = repos.GetMarca(); vm.Smartphones = repos.GetCelById(id); if (System.IO.File.Exists(Enviroment.WebRootPath + $"/CatalogoS/{vm.Smartphones.Id}.jpg")) { vm.Imagen = vm.Smartphones.Id + ".jpg"; } else { vm.Imagen = "NoDisp.jpg"; } return(View(vm)); }
public IActionResult Agregar(AdminCelularesViewModel vm) { Repository repos = new Repository(); try { if (vm.Archivo == null) { ModelState.AddModelError("", "Seleccione la imágen del celular."); vm.Marcas = repos.GetMarca(); return(View(vm)); } else { if (vm.Archivo.ContentType != "image/jpeg" || vm.Archivo.Length > 1024 * 1024 * 2) { ModelState.AddModelError("", "Debe seleccionar un archivo jpg de menos de 2MB."); vm.Marcas = repos.GetMarca(); return(View(vm)); } } repos.Agregar(vm.Smartphones); if (vm.Archivo != null) { FileStream fs = new FileStream(Enviroment.WebRootPath + "/CatalogoS/" + vm.Smartphones.Id + ".jpg", FileMode.Create); vm.Archivo.CopyTo(fs); fs.Close(); } return(RedirectToAction("Index", "Home")); } catch (Exception ex) { ModelState.AddModelError("", ex.Message); vm.Marcas = repos.GetMarca(); return(View(vm)); } }
public IActionResult Editar(AdminCelularesViewModel vm) { Repository repository = new Repository(); var celular = repository.GetCelById(vm.Smartphones.Id); try { vm.Marcas = repository.GetMarca(); if (celular != null) { celular.Caracteristicas.Bateria = vm.Smartphones.Caracteristicas.Bateria; celular.Caracteristicas.Camara = vm.Smartphones.Caracteristicas.Camara; celular.Caracteristicas.Peso = vm.Smartphones.Caracteristicas.Peso; celular.Caracteristicas.Precio = vm.Smartphones.Caracteristicas.Precio; celular.Caracteristicas.So = vm.Smartphones.Caracteristicas.So; celular.Caracteristicas.Tamaño = vm.Smartphones.Caracteristicas.Tamaño; celular.Nombre = vm.Smartphones.Nombre; celular.Pantalla = vm.Smartphones.Pantalla; celular.Procesador = vm.Smartphones.Procesador; celular.Ram = vm.Smartphones.Ram; celular.Expansion = vm.Smartphones.Expansion; celular.Descripcion = vm.Smartphones.Descripcion; celular.Almacenamiento = vm.Smartphones.Almacenamiento; repository.Editar(celular); return(RedirectToAction("Index", "Home")); } else { return(RedirectToAction("Index", "Home")); } } catch (Exception ex) { ModelState.AddModelError("", ex.Message); vm.Marcas = repository.GetMarca(); return(View(vm)); } }