public void SaveCopiedContent (int contentId, int categoryId, int languageId) { Category category = Category.Find(categoryId); CheckPermissions(category, Permission.Modify); if (category == null) { Flash["error"] = "Categoria padre inexistente"; RedirectToAction(Constants.CATEGORIES); return; } Content originalContent = Content.Find(contentId); Content content = new Content(category); content.Lang = Language.Find(languageId); if (content.Lang == null) { logger.Error("language is null!!!: " + languageId); return; } content.Save(); // Get an Id if (originalContent != null) { foreach(string key in originalContent.DataHash.Keys) // duplicate content { DataModel originalDataModel = (DataModel)originalContent.DataHash[key]; DataModel copyDataModel = new DataModel(content, originalDataModel.Field, originalDataModel.Value); content.DataHash[key] = copyDataModel; copyDataModel.Save(); } content.Save(); } //contentId = content.Id; // Read form inputs and attached files bool emptyForm = true; if (Request.Form.Count > 0 || Request.Files.Count > 0) { foreach (string input in Request.Form) { DataModel data; if (content.DataHash != null && content.DataHash.Contains(input)) { data = (DataModel) content.DataHash[input]; data.Value = Request.Form[input]; } else { Field field = Field.GetByName(input); if (field == null) continue; // invalid field name data = new DataModel(content, field, Request.Form[input]); } data.Save(); emptyForm = false; } foreach (string input in Request.Files.Keys) { DataModel data; System.Web.HttpPostedFile postedFile = Request.Files[input] as System.Web.HttpPostedFile; if ((postedFile == null) || (postedFile.FileName.Length == 0) || (postedFile.ContentLength == 0)) { logger.Debug("File not uploaded"); continue; } else if (content.DataHash != null && content.DataHash.Contains(input)) { data = (DataModel) content.DataHash[input]; File oldfile = (File) data.GetObjectFromValue(); File file = new File( config.GetValue(Constants.MEDIA_FOLDER)); file.SaveAttach(postedFile); data.Value = file.Id.ToString(); oldfile.RemoveAttach(); } else { Field field = Field.GetByName(input); if (field == null) continue; File file = new File(config.GetValue(Constants.MEDIA_FOLDER)); file.SaveAttach(postedFile); data = new DataModel(content, field, file.Id.ToString()); #if CACHE content.DataHash[input] = data; // force update cache #endif } data.Save(); emptyForm = false; } if (emptyForm) { content.Delete(); } else { bool isNew = true; foreach (Content c in category.ContentList) if (c.Id == content.Id) isNew = false; if (isNew) { category.ContentList.Add(content); category.ContentListSortedByReverseDate.Add(content); category.Save(); logger.Debug("save NEW content/category:" + content.Id +","+ category.Id); } else { content.Save(); category.Save(); logger.Debug("save NOT NEW content/category:" + content.Id +","+ category.Id); } } Hashtable parameters = new Hashtable(); parameters["Id"] = category.Id; RedirectToAction("viewcategory", parameters); } }
private static string ReadContent(XmlNode node) { try { if (node.Name == "Content") { Category category = (Category) NodeGetObject(node, Constants.GENERATOR_CATEGORYCODE, categories); if (category != null) { // string categorycode = NodeGetString(node, Constants.GENERATOR_CATEGORYCODE); string lang = NodeGetString(node, Constants.GENERATOR_LANG); DateTime creationdate = NodeGetDateTime(node, Constants.GENERATOR_CREATIONDATE); bool published = NodeGetBool(node, Constants.GENERATOR_PUBLISHED); bool frontpage = NodeGetBool(node, Constants.GENERATOR_FRONTPAGE); bool sectionfrontpage = NodeGetBool(node, Constants.GENERATOR_SECTIONFRONTPAGE); // Category category = Category.FindByCode(categorycode); Language l = Language.FindByName(lang); Content c = new Content(category, l, published, frontpage, sectionfrontpage, creationdate); c.Save(); contents[category.Code] = c; System.Console.WriteLine ("Content: "+ creationdate.ToString() + " " + category.Code); foreach (XmlNode n in node.ChildNodes) { if (n.Name == "DataModel") ReadDataModel(n, c); } } else { string categorycode = NodeGetString(node, Constants.GENERATOR_CATEGORYCODE); System.Console.WriteLine("No existe la categoria {0}", categorycode); } } return null; } catch(System.FormatException) { return "No se pudo leeer columna ordering"; } }
private void SavePortalContent (int contentId, int categoryId, string language) { Category category = Category.Find(categoryId); CheckPermissions(category, Permission.Modify); if (category == null) { RedirectToAction(Constants.CATEGORIES); return; } Content content; if (contentId != 0) { content = Content.Find (contentId); } else { content = new Content(category); Language lang = Language.FindByName(language); if (lang != null) content.Lang = lang; content.Save(); // r.Save(); } contentId = content.Id; // Read form inputs and attached files bool emptyForm = true; if (Request.Form.Count > 0 || Request.Files.Count > 0) { foreach (string input in Request.Form) { DataModel data; if (content.DataHash != null && content.DataHash.Contains(input)) { data = (DataModel) content.DataHash[input]; data.Value = Request.Form[input]; } else { Field field = Field.GetByName(input); if (field == null) continue; // invalid field name data = new DataModel(content, field, Request.Form[input]); } data.Save(); emptyForm = false; } foreach (string input in Request.Files.Keys) { DataModel data; System.Web.HttpPostedFile postedFile = Request.Files[input] as System.Web.HttpPostedFile; if ((postedFile == null) || (postedFile.FileName.Length == 0) || (postedFile.ContentLength == 0)) { logger.Debug("File not uploaded"); continue; } else if (content.DataHash != null && content.DataHash.Contains(input)) { data = (DataModel) content.DataHash[input]; File oldfile = (File) data.GetObjectFromValue(); File file = new File( config.GetValue(Constants.MEDIA_FOLDER)); file.SaveAttach(postedFile); data.Value = file.Id.ToString(); oldfile.RemoveAttach(); } else { Field field = Field.GetByName(input); if (field == null) continue; File file = new File(config.GetValue(Constants.MEDIA_FOLDER)); file.SaveAttach(postedFile); data = new DataModel(content, field, file.Id.ToString()); #if CACHE content.DataHash[input] = data; // force update cache #endif } data.Save(); emptyForm = false; } if (emptyForm) { content.Delete(); } else { bool isNew = true; foreach (Content c in category.ContentList) if (c.Id == content.Id) isNew = false; if (isNew) { category.ContentList.Add(content); category.ContentListSortedByReverseDate.Add(content); category.Save(); logger.Debug("save NEW content/category:" + content.Id +","+ category.Id); } else { content.Save(); category.Save(); logger.Debug("save NOT NEW content/category:" + content.Id +","+ category.Id); } } } }
private static string ReadContent(XmlNode node, Category c) { string keys = NodeGetString(node, "keys"); string vals = NodeGetString(node, "vals"); string[] colname = keys.Split(','); string[] namedescr = vals.Split(','); int l = colname.Length; Field [] f = new Field[l]; for (int i=0; i<l; i++) f[i] = Field.GetByName(colname[i]); Content r = new Content(c); r.Save(); for (int i=0; i<l; i++) { DataModel d = new DataModel(r, f[i], namedescr[i]); d.Save(); } return null; }