예제 #1
0
        public ActionResult Crear(CategoriaCosto categoriaCosto)
        {
            var yaExiste = Uow.CategoriasCostos.Listado().Any(cc => cc.Descripcion == categoriaCosto.Descripcion);

            if (yaExiste)
            {
                ModelState.AddModelError("Descripcion", "Ya existe una categoría con el mismo nombre");
            }

            if (categoriaCosto.PadreId != null)
            {
                var padre = Uow.CategoriasCostos.Obtener(categoriaCosto.PadreId.Value);
                if (padre.PadreId != null)
                {
                    ModelState.AddModelError("PadreId", "El padre seleccionado ya es a su vez hijo de otra categoría");
                }
            }

            if (!ModelState.IsValid)
            {
                return(PartialView(categoriaCosto));
            }
            categoriaCosto.Identifier = Guid.NewGuid();
            Uow.CategoriasCostos.Agregar(categoriaCosto);
            Uow.Commit();

            return(new JsonResult()
            {
                Data = new { exito = true }, JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
예제 #2
0
        public ActionResult Eliminar(CategoriaCosto categoriaCosto)
        {
            var hijas = Uow.CategoriasCostos.Listado().Where(x => !x.Eliminado && x.PadreId == categoriaCosto.CategoriaCostoId).ToList();

            foreach (var hija in hijas)
            {
                Uow.CategoriasCostos.Eliminar(hija);
            }
            Uow.CategoriasCostos.Eliminar(categoriaCosto);
            Uow.Commit();
            return(new JsonResult()
            {
                Data = new { exito = true }, JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
예제 #3
0
        public ActionResult Editar(CategoriaCosto categoriaCosto)
        {
            var yaExiste = Uow.CategoriasCostos.Listado().Any(cc => cc.Descripcion == categoriaCosto.Descripcion
                                                              &&
                                                              cc.CategoriaCostoId !=
                                                              categoriaCosto.CategoriaCostoId);

            if (yaExiste)
            {
                ModelState.AddModelError("Descripcion", "Ya existe una categoría con el mismo nombre");
            }

            if (categoriaCosto.PadreId != null)
            {
                if (categoriaCosto.CategoriaCostoId == categoriaCosto.PadreId)
                {
                    ModelState.AddModelError("PadreId", "El padre seleccionado debe ser diferente de la categoría que se está editando");
                }
                else
                {
                    var padre = Uow.CategoriasCostos.Obtener(categoriaCosto.PadreId.Value);
                    if (padre.PadreId != null)
                    {
                        ModelState.AddModelError("PadreId", "El padre seleccionado ya es a su vez hijo de otra categoría");
                    }
                }
            }

            if (!ModelState.IsValid)
            {
                return(PartialView(categoriaCosto));
            }



            Uow.CategoriasCostos.Modificar(categoriaCosto);
            Uow.Commit();
            return(new JsonResult()
            {
                Data = new { exito = true }, JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
예제 #4
0
        public ActionResult Editar(int id)
        {
            CategoriaCosto categoriaCosto = Uow.CategoriasCostos.Obtener(id);

            return(PartialView(categoriaCosto));
        }
예제 #5
0
        public ActionResult Detalle(int id)
        {
            CategoriaCosto categoriaCosto = Uow.CategoriasCostos.Obtener(u => u.CategoriaCostoId == id);

            return(PartialView(categoriaCosto));
        }