コード例 #1
0
        public JsonResult GetById(int id)
        {
            FamiliaProductoDAO dao = new FamiliaProductoDAO();
            familia_producto   c   = dao.GetById(id);

            var jsnResult = new
            {
                ID          = c.ID,
                NOMBRE      = c.NOMBRE,
                DESCRIPCION = c.DESCRIPCION,
                ACTIVO      = c.ACTIVO,
                Success     = true
            };

            return(Json(jsnResult, JsonRequestBehavior.AllowGet));
        }
コード例 #2
0
        public JsonResult Guardar(FamiliaProductoModel model)
        {
            var rm = new ResponseModel();

            if (!ModelState.IsValid)
            {
                rm.message  = "Hubo un problema verifique sus datos e intente de nuevo.";
                rm.message += ExtensionMethods.GetAllErrorsFromModelState(this);
                return(Json(rm, JsonRequestBehavior.AllowGet));
            }


            using (ArtexConnection db = new ArtexConnection())
            {
                FamiliaProductoDAO userDAO = new FamiliaProductoDAO();
                var entity = userDAO.GetById(model.Id, db);

                if (entity == null)
                {
                    entity             = new familia_producto();
                    entity.NOMBRE      = model.Nombre;
                    entity.DESCRIPCION = model.Descripcion;
                    entity.ACTIVO      = model.Activo;
                    db.familia_producto.Add(entity);
                }
                else
                {
                    entity.NOMBRE      = model.Nombre;
                    entity.DESCRIPCION = model.Descripcion;
                    entity.ACTIVO      = model.Activo;
                }

                if (db.SaveChanges() > 0 || db.Entry(entity).State == EntityState.Unchanged)
                {
                    rm.response = true;
                    rm.message  = "Sus datos se guardaron correctamente";
                    rm.function = "reload(true,'" + rm.message + "')";
                }
            }


            return(Json(rm, JsonRequestBehavior.AllowGet));
        }