[ValidateInput(false)]//不做html验证 public JsonResult ShowPage(string pagestr) { LessonUnitBll bll = new LessonUnitBll(); Page pageInfo = new Page(); JObject obj = JsonConvert.DeserializeObject(pagestr) as JObject; pageInfo.id = Convert.ToInt32(obj["id"]); pageInfo.pageNum = Convert.ToInt32(obj["pageNum"]); pageInfo.name = obj["name"].ToString(); pageInfo.steps = new List <Models.CurriculumSetViewModel.Step>(); JArray steps = JsonConvert.DeserializeObject(obj["steps"].ToString()) as JArray; foreach (var s in steps) { Models.CurriculumSetViewModel.Step step = new Models.CurriculumSetViewModel.Step(); step.stepNum = Convert.ToInt32(s["stepNum"]); step.actions = new List <ActionBase>(); JArray actions = JsonConvert.DeserializeObject(s["actions"].ToString()) as JArray; foreach (var a in actions) { step.actions.Add(ActionTranslator.JsonToViewData(a.ToString())); } pageInfo.steps.Add(step); } int coins = 0; var stepsData = pageInfo.steps.Select(s => new Domain.JsonEntity.UnitStep.Step() { id = s.id, StepNum = s.stepNum, Actions = s.actions.Select(a => ActionTranslator.ViewDataToData(a, ref coins)).ToList() }).ToList(); //保存数据到Radis中 bll.SaveUnitToRadis(new DtoLessonUnit { Id = pageInfo.id, Index = pageInfo.pageNum, Coins = coins, Steps = stepsData, Status = 0, }); string key = Encrypt.EncryptQueryString($"{new Random().Next(0, 10000)}_{pageInfo.id}_{0}_{0}"); return(Json(new JsonResponse <string> { State = true, ErrorCode = 0, ErrorMsg = "", Data = $"{ConfigurationManager.AppSettings["StudentClientDomain"]}LearningCenter/LessonApprove?ApproveKey={key}" })); }
[ValidateInput(false)]//不做html验证 public JsonResult SetPage(string pagestr) { LessonUnitBll bll = new LessonUnitBll(); Page pageInfo = new Page(); #region 解析数据 JObject obj = JsonConvert.DeserializeObject(pagestr) as JObject; string base64Str = obj["thumbnail"].ToString().Split(',')[1]; pageInfo.id = Convert.ToInt32(obj["id"]); pageInfo.pageNum = Convert.ToInt32(obj["pageNum"]); pageInfo.name = obj["name"].ToString(); string thumbnailPath = "UnitThumbnail"; //文件路径 string thumbnailFileName = $"unit{pageInfo.id}.png"; //文件名称 new Thread(() => { byte[] arr = Convert.FromBase64String(base64Str); MemoryStream ms = new MemoryStream(arr); FileManageClient client = new FileManageClient(ConfigurationManager.AppSettings["uploadUrl"]); var response = client.UploadCoverage(thumbnailFileName, ms, ConfigurationManager.AppSettings["OssSubject"], thumbnailPath, true); }).Start(); //开启线程上传缩略图片 pageInfo.thumbnail = $"/{thumbnailPath}/{thumbnailFileName}"; //拼接存储路径 pageInfo.steps = new List <Models.CurriculumSetViewModel.Step>(); JArray steps = JsonConvert.DeserializeObject(obj["steps"].ToString()) as JArray; foreach (var s in steps) { Models.CurriculumSetViewModel.Step step = new Models.CurriculumSetViewModel.Step(); step.stepNum = Convert.ToInt32(s["stepNum"]); step.actions = new List <ActionBase>(); JArray actions = JsonConvert.DeserializeObject(s["actions"].ToString()) as JArray; foreach (var a in actions) { step.actions.Add(ActionTranslator.JsonToViewData(a.ToString())); } pageInfo.steps.Add(step); } #endregion 解析数据 int coins = 0; var stepsData = pageInfo.steps.Select(s => new Domain.JsonEntity.UnitStep.Step() { id = s.id, StepNum = s.stepNum, Actions = s.actions.Select(a => ActionTranslator.ViewDataToData(a, ref coins)).ToList() }).ToList(); //修改数据 bll.Update(new DtoLessonUnit { Id = pageInfo.id, Name = pageInfo.name, Screenshot = pageInfo.thumbnail, Status = 0, Index = pageInfo.pageNum, Steps = stepsData, Coins = coins }); return(Json(new JsonResponse <string> { State = true, ErrorCode = 0, ErrorMsg = "", Data = "" })); }