Beispiel #1
0
        public IActionResult Eliminar(Categorias c)
        {
            //Fisica
            try
            {
                using (fruteriashopContext context = new fruteriashopContext())
                {
                    CategoriasRepository repos = new CategoriasRepository(context);
                    var categoria = repos.Get(c.Id);
                    repos.Delete(categoria);
                    return(RedirectToAction("Index"));
                }


                //Logico
                //using (fruteriashopContext context = new fruteriashopContext())
                //{

                //    CategoriasRepository repos = new CategoriasRepository(context);
                //    var categoria = repos.Get(c.Id);
                //    categoria.Eliminado = true;
                //    repos.Update(categoria);
                //    return RedirectToAction("Index");



                //}
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.Message);
                return(View(c));
            }
        }
Beispiel #2
0
        public IActionResult Index()
        {
            fruteriashopContext context = new fruteriashopContext();

            Repositories.Repository <Categorias> repos = new Repositories.Repository <Categorias>(context);
            return(View(repos.GetAll().OrderBy(x => x.Nombre)));
        }
Beispiel #3
0
        public IActionResult Eliminar(Categorias c)
        {
            try
            {
                // ELIMINACIÓN FISICA (SE BORRA COMPLETAMENTE DE LA BASE DE DATOS)
                //using (fruteriashopContext context = new fruteriashopContext())
                //{
                //    CategoriasRepository repos = new CategoriasRepository(context);
                //    var categoria = repos.Get(c.Id);
                //    repos.Delete(categoria);
                //    return RedirectToAction("Index");
                //}

                // ELIMINACION LOGICA (SE QUEDA EN LA BASE DE DATOS PERO CON UN CAMPO PARA ESPECIFICAR QUE ESTÁ ELIMINADA)
                using (fruteriashopContext context = new fruteriashopContext())
                {
                    CategoriasRepository repos = new CategoriasRepository(context);
                    var categoria = repos.Get(c.Id);
                    categoria.Eliminado = true;
                    repos.Update(categoria);
                    return(RedirectToAction("Index"));
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.Message);
                return(View(c));
            }
        }
Beispiel #4
0
        public IActionResult Eliminar(Categorias c)
        {
            try
            {
                // Modo físico: borra un registro de la db, operación delete.
                using (fruteriashopContext context = new fruteriashopContext())
                {
                    CategoriasRepository repos = new CategoriasRepository(context);
                    var categoria = repos.Get(c.Id);
                    repos.Delete(categoria);
                    return(RedirectToAction("Index"));
                }

                /* Modo lógico: marca el registro como eliminado, operación update.
                 * using (fruteriashopContext context = new fruteriashopContext())
                 * {
                 *  CategoriasRepository repos = new CategoriasRepository(context);
                 *  var categoria = repos.Get(c.Id);
                 *  categoria.Eliminado = true;
                 *  repos.Update(categoria);
                 *  return RedirectToAction("Index");
                 * } */
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.Message);
                return(View(c));
            }
        }
Beispiel #5
0
        public IActionResult Agregar(ProductosViewModel vm)
        {
            fruteriashopContext context = new fruteriashopContext();

            if (vm.Archivo.ContentType != "image/jpeg" || vm.Archivo.Length > 1024 * 1024 * 2)
            {
                ModelState.AddModelError("", "Debe selecionar un archivo jpg de menos de 2mb");
                CategoriasRepository categoriasRepository = new CategoriasRepository(context);
                vm.Categorias = categoriasRepository.GetAll();

                return(View(vm));
            }
            try
            {
                ProductosRepository repos = new ProductosRepository(context);
                repos.Insert(vm.Producto);
                //Guardar archivo de inserción
                FileStream fs = new FileStream(Environment.WebRootPath + "/img_frutas/" + vm.Producto.Id + ".jpg", FileMode.Create);
                vm.Archivo.CopyTo(fs);
                fs.Close();

                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.Message);
                CategoriasRepository categoriasRepository = new CategoriasRepository(context);
                vm.Categorias = categoriasRepository.GetAll();

                return(View(vm));
            }
        }
Beispiel #6
0
        public IActionResult Editar(int id)
        {
            fruteriashopContext context = new fruteriashopContext();
            ProductosViewModel  vm      = new ProductosViewModel();

            ProductosRepository pr = new ProductosRepository(context);

            vm.Producto = pr.Get(id);
            if (vm.Producto == null)
            {
                return(RedirectToAction("Index"));
            }
            CategoriasRepository cr = new CategoriasRepository(context);

            vm.Categorias = cr.GetAll();
            if (System.IO.File.Exists(Environment.WebRootPath + $"/img_frutas/{vm.Producto.Id}.jpg"))
            {
                vm.Imagen = vm.Producto.Id + ".jpg";
            }
            else
            {
                vm.Imagen = "no-disponible.png";
            }

            return(View(vm));
        }
Beispiel #7
0
        public IActionResult Editar(int Id)
        {
            fruteriashopContext context = new fruteriashopContext();
            ProductosRepository repos   = new ProductosRepository(context);
            ProductosViewModel  vm      = new ProductosViewModel();

            vm.Producto = repos.Get(Id);

            if (vm.Producto == null)
            {
                return(RedirectToAction("Index"));
            }

            CategoriasRepository cr = new CategoriasRepository(context);

            vm.Categorias = cr.GetAll().Where(x => x.Eliminado == false).OrderBy(x => x.Nombre);

            if (System.IO.File.Exists(Enviroment.WebRootPath + $"/img_frutas/{vm.Producto.Id}.jpg"))
            {
                vm.Imagen = vm.Producto.Id + ".jpg";
            }
            else
            {
                vm.Imagen = "no-disponible.png";
            }

            return(View(vm));
        }
Beispiel #8
0
        public IActionResult Editar(Categorias nuevo)
        {
            try
            {
                using (fruteriashopContext context = new fruteriashopContext())
                {
                    CategoriasRepository repos = new CategoriasRepository(context);

                    var original = repos.Get(nuevo.Id);

                    if (original != null)
                    {
                        original.Nombre = nuevo.Nombre;
                        repos.Update(original);
                    }

                    return(RedirectToAction("Index"));
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.Message);
                return(View(nuevo));
            }
        }
Beispiel #9
0
 public CategoriasService()
 {
     using (fruteriashopContext context = new fruteriashopContext())
     {
         Repository <Categorias> repos = new Repository <Categorias>(context);
         Categorias = repos.GetAll().Where(x => x.Eliminado == false).OrderBy(x => x.Nombre).ToList();
     }
 }
Beispiel #10
0
 public CategoriaService()
 {
     using (fruteriashopContext context = new fruteriashopContext())
     {
         Repositories.Repository <Categorias> repos = new Repositories.Repository <Categorias>(context);
         Categorias = repos.GetAll().OrderBy(x => x.Nombre).ToList();
     }
 }
Beispiel #11
0
        public IActionResult Agregar()
        {
            ProductosViewModel   vm      = new ProductosViewModel();
            fruteriashopContext  context = new fruteriashopContext();
            CategoriasRepository categoriasRepository = new CategoriasRepository(context);

            vm.Categorias = categoriasRepository.GetAll();
            return(View(vm));
        }
Beispiel #12
0
        public IActionResult Agregar()
        {
            ProductosViewModel   vm      = new ProductosViewModel();
            fruteriashopContext  context = new fruteriashopContext();
            CategoriasRepository repos   = new CategoriasRepository(context);

            vm.Categorias = repos.GetAll().Where(x => x.Eliminado == false).OrderBy(x => x.Nombre);
            return(View(vm));
        }
 public IActionResult Ver(string categoria, string id)
 {
     using (fruteriashopContext context = new fruteriashopContext())
     {
         ProductosRepository repos = new ProductosRepository(context);
         Productos           p     = repos.GetProductosByCategoriaNombre(categoria, id.Replace("-", " "));
         return(View(p));
     }
 }
        public IActionResult Agregar(ProductosViewModel pvm)
        {
            fruteriashopContext context = new fruteriashopContext();

            //guardar el archivo de la imagen


            try
            {
                if (pvm.Archivo == null)
                {
                    ModelState.AddModelError("", "Debe seleccionar una imagen para el producto");
                    CategoriasRepository categoriasRepository = new CategoriasRepository(context);

                    pvm.Categorias = categoriasRepository.GetAll();

                    return(View(pvm));
                }
                else
                {
                    if (pvm.Archivo.ContentType != "image/jpeg" || pvm.Archivo.Length > 1024 * 1024 * 2)
                    {
                        ModelState.AddModelError("", "Debe seleccionar un archivo jpg de menos de 2MB.");
                        CategoriasRepository categoriasRepository = new CategoriasRepository(context);

                        pvm.Categorias = categoriasRepository.GetAll();

                        return(View(pvm));
                    }
                }


                ProductosRepository repos = new ProductosRepository(context);

                repos.Insert(pvm.Producto);

                if (pvm.Archivo != null)
                {
                    FileStream fs = new FileStream(Enviroment.WebRootPath + "/img_frutas/" + pvm.Producto.Id + ".jpg", FileMode.Create);
                    pvm.Archivo.CopyTo(fs);
                    fs.Close();
                }



                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.Message);
                CategoriasRepository categoriasRepository = new CategoriasRepository(context);

                pvm.Categorias = categoriasRepository.GetAll();

                return(View(pvm));
            }
        }
Beispiel #15
0
        public IActionResult Index()
        {
            fruteriashopContext     context = new fruteriashopContext();
            Repository <Categorias> repos   = new Repository <Categorias>(context);

            /// RETURN PARA ELIMINACIÓN FISICA
            //return View(repos.GetAll().OrderBy(x => x.Nombre));
            // RETURN PARA ELIMINACION LOGICA
            return(View(repos.GetAll().Where(x => x.Eliminado == false).OrderBy(x => x.Nombre)));
        }
        public IActionResult Index(ProductosIndexViewModel vm)
        {
            fruteriashopContext  context         = new fruteriashopContext();
            CategoriasRepository categoriasRepos = new CategoriasRepository(context);
            ProductosRepository  productosRepos  = new ProductosRepository(context);

            vm.Categorias = categoriasRepos.GetAll();
            vm.Productos  = productosRepos.GetProductosByCategoria(vm.IdCategoria);
            return(View(vm));
        }
        public IActionResult Ver(string categoria, string id)
        {
            using (fruteriashopContext context = new fruteriashopContext())//el contexto no se instancia dentro del repositorio ya que no queremos que se hagan multiples conexiones
            {
                ProductosRepository repos = new ProductosRepository(context);

                Productos p = repos.GetProductosbyCategoriaNombre(categoria, id.Replace("-", " "));

                return(View(p));
            }
        }
 public IActionResult Categoria(string id)
 {
     using (fruteriashopContext context = new fruteriashopContext())
     {
         ProductosRepository repos = new ProductosRepository(context);
         CategoriaViewModel  vm    = new CategoriaViewModel();
         vm.Nombre    = id;
         vm.Productos = repos.GetProductosByCategoria(id).ToList();
         return(View(vm));
     }
 }
Beispiel #19
0
        public IActionResult Index()
        {
            ProductosIndexViewModel pivm    = new ProductosIndexViewModel();
            fruteriashopContext     context = new fruteriashopContext();
            CategoriasRepository    cr      = new CategoriasRepository(context);
            ProductosRepository     pr      = new ProductosRepository(context);
            int?id = null;

            pivm.Categorias = cr.GetAll();
            pivm.Productos  = pr.GetProductosByCategoria(id);
            return(View(pivm));
        }
        public IActionResult Editar(ProductosViewModel pvm)
        {
            fruteriashopContext context = new fruteriashopContext();


            if (pvm.Archivo != null)
            {
                if (pvm.Archivo.ContentType != "image/jpeg" || pvm.Archivo.Length > 1024 * 1024 * 2)
                {
                    ModelState.AddModelError("", "Debe seleccionar un archivo jpg de menos de 2MB.");
                    CategoriasRepository categoriasRepository = new CategoriasRepository(context);

                    pvm.Categorias = categoriasRepository.GetAll();

                    return(View(pvm));
                }
            }
            try
            {
                ProductosRepository repos = new ProductosRepository(context);
                //busca el producto que queremos editar
                var p = repos.Get(pvm.Producto.Id);

                if (p != null)
                {
                    p.Nombre       = pvm.Producto.Nombre;
                    p.IdCategoria  = pvm.Producto.IdCategoria;
                    p.Precio       = pvm.Producto.Precio;
                    p.Descripcion  = pvm.Producto.Descripcion;
                    p.UnidadMedida = pvm.Producto.UnidadMedida;
                    repos.Update(p);
                }

                if (pvm.Archivo != null)
                {
                    FileStream fs = new FileStream(Enviroment.WebRootPath + "/img_frutas/" + pvm.Producto.Id + ".jpg", FileMode.Create);
                    pvm.Archivo.CopyTo(fs);
                    fs.Close();
                }

                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.Message);
                CategoriasRepository categoriasRepository = new CategoriasRepository(context);

                pvm.Categorias = categoriasRepository.GetAll();

                return(View(pvm));
            }
        }
        public IActionResult Categoria(string id)
        {
            using (fruteriashopContext context = new fruteriashopContext())
            {
                //fruteriashopContext context = new fruteriashopContext();
                ProductosRepository repos = new ProductosRepository(context);

                CategoriaViewModel vm = new CategoriaViewModel();
                vm.Nombre    = id;
                vm.Productos = repos.GetProductosByCategoria(id).ToList();//to list es mas rapido porque no lo consulta en la bd si no que ya se encuentra en la memoria
                return(View(vm));
            }
        }
Beispiel #22
0
 public IActionResult Editar(int id)
 {
     using (fruteriashopContext context = new fruteriashopContext())
     {
         CategoriasRepository repos = new CategoriasRepository(context);
         var categoria = repos.Get(id);
         if (categoria == null)
         {
             return(RedirectToAction("Index"));
         }
         return(View(categoria));
     }
 }
Beispiel #23
0
        public IActionResult Index()
        {
            ProductosIndexViewModel vm      = new ProductosIndexViewModel();
            fruteriashopContext     context = new fruteriashopContext();
            CategoriasRepository    categoriasRepository = new CategoriasRepository(context);
            ProductosRepository     productosRepository  = new ProductosRepository(context);

            int?id = null;

            vm.Categorias = categoriasRepository.GetAll().Where(x => x.Eliminado == 0);
            vm.Productos  = productosRepository.GetProductosByCategoria(id);

            return(View(vm));
        }
Beispiel #24
0
 public IActionResult Agregar(Categorias c)
 {
     try
     {
         fruteriashopContext  context = new fruteriashopContext();
         CategoriasRepository repos   = new CategoriasRepository(context);
         repos.Insert(c);
         return(RedirectToAction("Index"));
     }
     catch (Exception ex)
     {
         ModelState.AddModelError("", ex.Message);
         return(View(c));
     }
 }
        public IActionResult Index()
        {
            ProductosIndexViewModel vm      = new ProductosIndexViewModel();
            fruteriashopContext     context = new fruteriashopContext();
            //Una sola conexion pero dla utilizan los dos repositorios
            CategoriasRepository categoriasrepository = new CategoriasRepository(context);
            ProductosRepository  productosRepository  = new ProductosRepository(context);

            int?id = 0;

            vm.Categorias = categoriasrepository.GetAll();
            vm.Productos  = productosRepository.GetProductosByCategoria(id);

            return(View(vm));
        }
Beispiel #26
0
        public IActionResult Editar(ProductosViewModel vm)
        {
            fruteriashopContext context = new fruteriashopContext();

            if (vm.Archivo != null)
            {
                if (vm.Archivo.ContentType != "image/jpeg" || vm.Archivo.Length > 1024 * 1024 * 2)
                {
                    ModelState.AddModelError("", "Debe seleccionar un archivo jpg de menos de 2MB.");
                    CategoriasRepository repos = new CategoriasRepository(context);
                    vm.Categorias = repos.GetAll().Where(x => x.Eliminado == false).OrderBy(x => x.Nombre);
                    return(View(vm));
                }
            }

            try
            {
                ProductosRepository repos = new ProductosRepository(context);

                var producto = repos.Get(vm.Producto.Id);

                if (producto != null)
                {
                    producto.Nombre       = vm.Producto.Nombre;
                    producto.Precio       = vm.Producto.Precio;
                    producto.IdCategoria  = vm.Producto.IdCategoria;
                    producto.Descripcion  = vm.Producto.Descripcion;
                    producto.UnidadMedida = vm.Producto.UnidadMedida;
                    repos.Update(producto);

                    if (vm.Archivo != null)
                    {
                        FileStream fs = new FileStream(Enviroment.WebRootPath + "/img_frutas/" + vm.Producto.Id + ".jpg", FileMode.Create);
                        vm.Archivo.CopyTo(fs);
                        fs.Close();
                    }
                }

                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.Message);
                CategoriasRepository repos = new CategoriasRepository(context);
                vm.Categorias = repos.GetAll().OrderBy(x => x.Nombre);
                return(View(vm));
            }
        }
Beispiel #27
0
 public IActionResult Eliminar(int id)
 {
     using (fruteriashopContext context = new fruteriashopContext())
     {
         ProductosRepository repos = new ProductosRepository(context);
         var p = repos.Get(id);
         if (p != null)
         {
             return(View(p));
         }
         else
         {
             return(RedirectToAction("Index"));
         }
     }
 }
Beispiel #28
0
        public IActionResult Index()
        {
            ProductosIndexViewModel vm             = new ProductosIndexViewModel();
            fruteriashopContext     context        = new fruteriashopContext();
            CategoriasRepository    categoriarepos = new CategoriasRepository(context);
            ProductosRepository     productosrepos = new ProductosRepository(context);


            int?id = null;

            // AGREGUÉ EL WHERE PARA QUE NO SE MUESTRE LA CATEGORÍA SI FUÉ ELIMINADA DE MANERA LOGICA
            vm.Categorias = categoriarepos.GetAll().Where(x => x.Eliminado == false).OrderBy(x => x.Nombre);
            vm.Productos  = productosrepos.GetProductosByCategoria(id);


            return(View(vm));
        }
Beispiel #29
0
        public IActionResult Agregar(ProductosViewModel vm)
        {
            fruteriashopContext context = new fruteriashopContext();

            try
            {
                if (vm.Archivo == null)
                {
                    ModelState.AddModelError("", "Debe seleccionar la imagen del producto.");
                    CategoriasRepository categoriasrepos = new CategoriasRepository(context);
                    vm.Categorias = categoriasrepos.GetAll().Where(x => x.Eliminado == false).OrderBy(x => x.Nombre);
                    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.");
                        CategoriasRepository repos = new CategoriasRepository(context);
                        vm.Categorias = repos.GetAll().Where(x => x.Eliminado == false).OrderBy(x => x.Nombre);
                        return(View(vm));
                    }
                }


                ProductosRepository productosrepos = new ProductosRepository(context);
                productosrepos.Insert(vm.Producto);

                if (vm.Archivo != null)
                {
                    FileStream fs = new FileStream(Enviroment.WebRootPath + "/img_frutas/" + vm.Producto.Id + ".jpg", FileMode.Create);
                    vm.Archivo.CopyTo(fs);
                    fs.Close();
                }

                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.Message);
                CategoriasRepository repos = new CategoriasRepository(context);
                vm.Categorias = repos.GetAll().OrderBy(x => x.Nombre);
                return(View(vm));
            }
        }
 public IActionResult Eliminar(Categorias c)
 {
     try
     {
         using (fruteriashopContext context = new fruteriashopContext())
         {
             CategoriasRepository repos = new CategoriasRepository(context);
             var categoria = repos.Get(c.Id);
             repos.Delete(categoria);
             return(RedirectToAction("Index"));
         }
     }
     catch (Exception ex)
     {
         ModelState.AddModelError("", ex.Message);
         return(View(c));
     }
 }