public string SaveEntry(MinutesDocument entry) { string newId = "ono"; try { string lodgeFileName = Server.MapPath("\\App_Data\\") + MasonMasterData.GetUserProfile(User.Identity.Name).DatabaseName; newId = MemberDataXml.MinutesAddEdit(entry, lodgeFileName); //var serializer = new System.Web.Script.Serialization.JavaScriptSerializer(); //success = serializer.Serialize(blogEntry); } catch (Exception ex) { newId = "ERROR: " + ex.Message; } return newId; }
public JsonResult GetEntry(string blogId) { MinutesDocument entry = new MinutesDocument(); try { string lodgeFileName = Server.MapPath("\\App_Data\\") + MasonMasterData.GetUserProfile(User.Identity.Name).DatabaseName; XmlDocument xdoc = new XmlDocument(); xdoc.Load(lodgeFileName); XmlNode blogEntryNode = xdoc.SelectSingleNode("//Minutes//Entry[@Id='" + blogId + "']"); entry.Date = Convert.ToDateTime(blogEntryNode.Attributes["DateCreated"].InnerText).ToString("MM/dd/yyyy"); entry.Title = blogEntryNode.Attributes["Title"].InnerText; entry.Id = blogId; entry.Minutes = blogEntryNode.ChildNodes[0].InnerText; //var serializer = new System.Web.Script.Serialization.JavaScriptSerializer(); //success = serializer.Serialize(blogEntry); } catch (Exception ex) { entry.Minutes = ex.Message; } return Json(new { Data = entry }, JsonRequestBehavior.AllowGet); }
public static string MinutesAddEdit(MinutesDocument entry, string xmlFileName) { XmlDocument xdoc = new XmlDocument(); xdoc.Load(xmlFileName); XmlNode MinutesNode = xdoc.SelectSingleNode("//Minutes"); XmlNode entryNode = null; if (entry.Id == null) { entry.Id = Guid.NewGuid().ToString(); entryNode = xdoc.CreateElement("Entry"); XmlAttribute Title = xdoc.CreateAttribute("Title"); Title.Value = entry.Title; entryNode.Attributes.Append(Title); XmlAttribute DateCreated = xdoc.CreateAttribute("DateCreated"); DateCreated.Value = entry.Date; entryNode.Attributes.Append(DateCreated); XmlAttribute Id = xdoc.CreateAttribute("Id"); Id.Value = entry.Id; entryNode.Attributes.Append(Id); XmlCDataSection Minutes = xdoc.CreateCDataSection(entry.Minutes); entryNode.AppendChild(Minutes); MinutesNode.AppendChild(entryNode); } else { entryNode = xdoc.SelectSingleNode("//Minutes//Entry[@Id='" + entry.Id + "']"); entryNode.Attributes["Title"].Value = entry.Title; entryNode.Attributes["DateCreated"].Value = entry.Date; entryNode.ChildNodes[0].Value = entry.Minutes; } xdoc.Save(xmlFileName); return entry.Id; }