public JsonResult Save(data.tbticket ticke) { data.tbticket entity; using (var db = data.Entities.NewInstance) { if (ticke.uid > 0) { entity = db.tbtickets.First(p => p.uid == ticke.uid); entity.scene_str = ticke.scene_str; entity.expire_seconds = ticke.expire_seconds; entity.note = ticke.note; } else { var requstUrl = string.Format("https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token={0}", GetAccessToken()); var jsonParam = JsonConvert.SerializeObject(new { expire_seconds = ticke.expire_seconds, action_name = "QR_STR_SCENE", action_info = new { scene = new { scene_str = ticke.scene_str } } }); var jsonResult = PostJson(requstUrl, jsonParam); var json = JsonConvert.DeserializeObject <dynamic>(jsonResult); db.tbtickets.Add(new data.tbticket { action_name = "QR_STR_SCENE", expire_seconds = ticke.expire_seconds, note = ticke.note, create_time = DateTime.Now.Ticks, scene_str = ticke.scene_str, ticket = json.ticket, url = json.url, status = 0 }); } db.SaveChanges(); } return(Json(new { result = true })); }
public JsonResult Delete(int uid) { using (var db = data.Entities.NewInstance) { data.tbticket entity = db.tbtickets.First(p => p.uid == uid); if (entity != null) { entity.status = 1; } db.SaveChanges(); } return(Json(new { result = true })); }