public void ImportModule(int moduleId, string Content, string version, int userId) { var module = new OpenContentModuleInfo(moduleId, Null.NullInteger); var index = module.Settings.Template.Manifest.Index; var indexConfig = OpenContentUtils.GetIndexConfig(module.Settings.Template); OpenContentController ctrl = new OpenContentController(); XmlNode xml = Globals.GetContent(Content, "opencontent"); foreach (XmlNode item in xml.SelectNodes("item")) { XmlNode json = item.SelectSingleNode("json"); XmlNode collection = item.SelectSingleNode("collection"); XmlNode key = item.SelectSingleNode("key"); var contentInfo = new OpenContentInfo() { ModuleId = moduleId, Collection = collection?.InnerText ?? "", Key = key?.InnerText ?? "", Json = item.InnerText, CreatedByUserId = userId, CreatedOnDate = DateTime.Now, LastModifiedByUserId = userId, LastModifiedOnDate = DateTime.Now, Title = "" }; ctrl.AddContent(contentInfo, index, indexConfig); } }
public HttpResponseMessage Add(UpdateRequest req) { try { ModuleController mc = new ModuleController(); var requestModule = mc.GetModule(req.ModuleId, req.TabId, false); bool index = false; OpenContentSettings settings = requestModule.OpenContentSettings(); ModuleInfo module = requestModule; if (settings.ModuleId > 0) { module = mc.GetModule(settings.ModuleId, settings.TabId, false); } var manifest = settings.Template.Manifest; TemplateManifest templateManifest = settings.Template; index = settings.Template.Manifest.Index; string editRole = manifest.GetEditRole(); bool listMode = templateManifest != null && templateManifest.IsListTemplate; int createdByUserid = -1; OpenContentController ctrl = new OpenContentController(); if (listMode) { if (!OpenContentUtils.HasEditPermissions(PortalSettings, module, editRole, createdByUserid)) { return(Request.CreateResponse(HttpStatusCode.Unauthorized)); } var indexConfig = OpenContentUtils.GetIndexConfig(settings.Template.Key.TemplateDir); OpenContentInfo content = new OpenContentInfo() { ModuleId = module.ModuleID, Title = ActiveModule.ModuleTitle, Json = req.json.ToString(), JsonAsJToken = req.json, CreatedByUserId = UserInfo.UserID, CreatedOnDate = DateTime.Now, LastModifiedByUserId = UserInfo.UserID, LastModifiedOnDate = DateTime.Now, Html = "", }; ctrl.AddContent(content, index, indexConfig); return(Request.CreateResponse(HttpStatusCode.OK, "")); } else { return(Request.CreateResponse(HttpStatusCode.BadRequest, "It's not a list mode module")); } } catch (Exception exc) { Log.Logger.Error(exc); return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, exc)); } }
public HttpResponseMessage Add(UpdateRequest req) { try { var module = new OpenContentModuleInfo(req.ModuleId, req.TabId); string editRole = module.Settings.Template.Manifest.GetEditRole(); OpenContentController ctrl = new OpenContentController(); if (module.IsListMode()) { if (!OpenContentUtils.HasEditPermissions(PortalSettings, module.ViewModule, editRole, -1)) { Log.Logger.WarnFormat("Failed the HasEditPermissions() check for "); return(Request.CreateResponse(HttpStatusCode.Unauthorized, "Failed the HasEditPermissions() check")); } var index = module.Settings.Template.Manifest.Index; var indexConfig = OpenContentUtils.GetIndexConfig(module.Settings.Template.Key.TemplateDir, "Items"); OpenContentInfo content = new OpenContentInfo() { ModuleId = module.DataModule.ModuleID, Collection = req.Collection, Title = ActiveModule.ModuleTitle, Json = req.json.ToString(), CreatedByUserId = UserInfo.UserID, CreatedOnDate = DateTime.Now, LastModifiedByUserId = UserInfo.UserID, LastModifiedOnDate = DateTime.Now }; ctrl.AddContent(content, index, indexConfig); return(Request.CreateResponse(HttpStatusCode.OK, "")); } else { return(Request.CreateResponse(HttpStatusCode.BadRequest, "It's not a list mode module")); } } catch (Exception exc) { Log.Logger.Error(exc); return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, exc)); } }