コード例 #1
0
ファイル: SegmentoController.cs プロジェクト: LuisAP/Artex
        public JsonResult GetById(int id)
        {
            SegmentoDAO dao = new SegmentoDAO();
            segmento    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 segmento GetById(int id, ArtexConnection dbContext = null)
        {
            segmento consulta = null;

            try
            {
                dbContext = dbContext != null ? dbContext : new ArtexConnection();

                consulta = dbContext.segmento.Where(e => e.ID == id).FirstOrDefault();
            }
            catch (Exception e)
            {
            }

            return(consulta);
        }
コード例 #3
0
ファイル: SegmentoController.cs プロジェクト: LuisAP/Artex
        public JsonResult Guardar(SegmentoModel 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())
            {
                SegmentoDAO dao    = new SegmentoDAO();
                var         entity = dao.GetById(model.Id, db);

                if (entity == null)
                {
                    entity             = new segmento();
                    entity.NOMBRE      = model.Nombre;
                    entity.DESCRIPCION = model.Descripcion;
                    entity.ACTIVO      = model.Activo;
                    db.segmento.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));
        }