示例#1
0
        public ActionResult EditDef_PenaltyEnd(Def_Penalty Def_Penalty)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var obj = db.Def_Penalty.Where(a => a.ID == Def_Penalty.ID).FirstOrDefault();
                    obj.Name    = Def_Penalty.Name;
                    obj.Value   = Def_Penalty.Value;
                    obj.Daysnum = Def_Penalty.Daysnum;

                    db.SaveChanges();
                    var ob = JsonConvert.SerializeObject(db.Def_Penalty.Select(a => new { ID = a.ID, Name = a.Name, Value = a.Value, Daysnum = a.Daysnum }).ToList());
                    return(Json(new { action = "yes", msg = "Editted", result = ob }, JsonRequestBehavior.AllowGet));
                }
                catch (Exception ex)
                {
                    var ob = JsonConvert.SerializeObject(db.Def_Penalty.Select(a => new { ID = a.ID, Name = a.Name, Value = a.Value, Daysnum = a.Daysnum }).ToList());
                    return(Json(new { action = "no", msg = "error occurred", result = ob }, JsonRequestBehavior.AllowGet));
                }
            }
            else
            {
                var ob = JsonConvert.SerializeObject(db.Def_Penalty.Select(a => new { ID = a.ID, Name = a.Name, Value = a.Value, Daysnum = a.Daysnum }).ToList());
                return(Json(new { action = "yes", msg = "error occurred", result = ob }, JsonRequestBehavior.AllowGet));
            }
        }
示例#2
0
 public ActionResult AddDef_PenaltyEnd(Def_Penalty Def_Penalty)
 {
     if (ModelState.IsValid)
     {
         try {
             db.Def_Penalty.Add(Def_Penalty);
             db.SaveChanges();
             var ob = JsonConvert.SerializeObject(db.Def_Penalty.Select(a => new { ID = a.ID, Name = a.Name, Value = a.Value, Daysnum = a.Daysnum }).ToList());
             return(Json(new { action = "yes", msg = "Added", result = ob }, JsonRequestBehavior.AllowGet));
         }
         catch (Exception ex)
         {
             return(Json(new { action = "no", msg = "error occurred", result = "" }, JsonRequestBehavior.AllowGet));
         }
     }
     else
     {
         var ob = JsonConvert.SerializeObject(db.Def_Penalty.Select(a => new { ID = a.ID, Name = a.Name, Value = a.Value, Daysnum = a.Daysnum }).ToList());
         return(Json(new { action = "no", msg = "error occurred", result = ob }, JsonRequestBehavior.AllowGet));
     }
 }