public JsonResult TempAdd(int OrderID, string TempDesc, string FolderName, string TempName, string Content, string extention, string namespaceStr, int TempType, string fileName) { ModelForJson data = new ModelForJson(); try { string localURL = System.Configuration.ConfigurationManager.AppSettings["tempLocation"]; if (!string.IsNullOrEmpty(Content) && !string.IsNullOrEmpty(TempName)) { string tempURL = localURL + "\\" + TempName + ".cshtml"; string path = Server.MapPath(tempURL); if (FileHelper.IsExistFile(path)) { data.Status = 0; data.Desc = "已存在相同模板,无法添加!"; } else { FileHelper.CreateFile(path); FileHelper.WriteText(path, Content); Data.TempInfo infoModel = new Data.TempInfo(); infoModel.TP_Order = OrderID; infoModel.TP_Desc = TempDesc; infoModel.TP_FolderName = FolderName; infoModel.TP_Name = TempName; infoModel.TP_AddDate = DateTime.Now.ToString(); infoModel.TP_URL = tempURL; infoModel.TP_IsSysTemp = 0; infoModel.TP_Extention = extention; infoModel.TP_NameSpace = namespaceStr; infoModel.TP_Type = TempType; infoModel.TP_FileName = fileName; context.TempInfo.Add(infoModel); context.SaveChanges(); data.Status = 1; data.Desc = "保存成功!"; } } else { data.Status = 0; data.Desc = "模板名或模板内容不能为空!"; } } catch (Exception ex) { data.Status = 0; data.Desc = ex.Message; } return(Json(data)); }
/// <summary> /// 添加模板 /// </summary> /// <returns></returns> public ActionResult TempAdd() { Data.TempInfo model = new Data.TempInfo() { TP_Order = 100, TP_FolderName = "FolderName", TP_Type = (int)Data.TemplateType.DataFirst }; return(View(model)); }