コード例 #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));
            }
        }
コード例 #2
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));
            }
        }
コード例 #3
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));
            }
        }
コード例 #4
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));
            }
        }
コード例 #5
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));
     }
 }
コード例 #6
0
 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));
     }
 }
コード例 #7
0
        public IActionResult Eliminar(int id)
        {
            //Eliminacion fisica
            using (fruteriashopContext context = new fruteriashopContext())
            {
                CategoriasRepository repos = new CategoriasRepository(context);
                var categoriaBd            = repos.Get(id);

                if (categoriaBd == null)
                {
                    return(RedirectToAction("Index"));
                }
                else
                {
                    return(View(categoriaBd));
                }
            }
        }
コード例 #8
0
        public IActionResult Eliminar(Categorias categoriaTemporal)
        {
            //try
            //{
            //    //ELIMINACION FISICA
            //    using(fruteriashopContext context = new fruteriashopContext())
            //    {
            //        CategoriasRepository repos = new CategoriasRepository(context);

            //        var categoriaBD = repos.Get(categoriaTemporal.Id);
            //        repos.Delete(categoriaBD);

            //        return RedirectToAction("Index");
            //    }

            //}
            //catch (Exception ex)
            //{
            //    ModelState.AddModelError("", ex.Message);
            //    return View(categoriaTemporal);
            //}

            //ELIMINACION LOGICA

            try
            {
                using (fruteriashopContext context = new fruteriashopContext())
                {
                    CategoriasRepository repos = new CategoriasRepository(context);

                    var categoriaBD = repos.Get(categoriaTemporal.Id);
                    categoriaBD.Eliminado = true;
                    repos.Update(categoriaBD);

                    return(RedirectToAction("Index"));
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.Message);
                return(View(categoriaTemporal));
            }
        }
コード例 #9
0
        public IActionResult Editar(Categorias categoriaTemporal)
        {
            try
            {
                using (fruteriashopContext context = new fruteriashopContext())
                {
                    CategoriasRepository repos = new CategoriasRepository(context);
                    var categoriaBd            = repos.Get(categoriaTemporal.Id);

                    if (categoriaBd != null)
                    {
                        categoriaBd.Nombre = categoriaTemporal.Nombre;
                        repos.Update(categoriaBd);
                    }

                    return(RedirectToAction("Index"));
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.Message);
                return(View(categoriaTemporal));
            }
        }