Ejemplo n.º 1
0
 public void Add(WikiEntry entry)
 {
     if (entry == null)
     {
         throw new NullReferenceException("Null");
     }
     Entries.Add(entry);
     entry.Status = EntityStatus.Inserted;
 }
Ejemplo n.º 2
0
        public static void CreateEntry(WikiEntry entry)
        {
            foreach (var item in entry.Categories)
            {
                string categoryId = "";

                // Category exists
                if (XCategories.Any(c => c.Attribute("Text").Value == item.Text))
                {
                    continue;
                }
                else
                {
                    // Generate new Category
                    categoryId = (Convert.ToInt32(XCategories.Last().Attribute("Id").Value) + 1).ToString();

                    XCategory.Add(
                        new XElement("Category",
                                     new XAttribute("Id", categoryId),
                                     new XAttribute("Text", item.Text))
                        );
                }
            }

            foreach (var item in entry.Tags)
            {
                string tagId = "";

                // Tag exists
                if (XTags.Any(c => c.Attribute("Text").Value == item.Text))
                {
                    continue;
                }
                else
                {
                    // Generate new Tag
                    tagId = (Convert.ToInt32(XTags.Last().Attribute("Id").Value) + 1).ToString();
                    XTag.Add
                    (
                        new XElement("Tag",
                                     new XAttribute("Id", tagId),
                                     new XAttribute("Text", item.Text))
                    );
                }
            }

            XElement wikiEntry =
                new XElement("WikiEntry",
                             new XAttribute("Id", Guid.NewGuid()),
                             new XAttribute("CreatedBy", "*****@*****.**"),
                             new XAttribute("CreatedAt", DateTimeOffset.UtcNow.ToString()),
                             new XAttribute("UpdatedBy", "*****@*****.**"),
                             new XAttribute("UpdatedAt", DateTimeOffset.UtcNow.ToString()),
                             new XAttribute("CategoryIds", string.Join(",", from x in entry.Categories select x.Id)),
                             new XAttribute("TagIds", string.Join(",", from x in entry.Tags select x.Id)),
                             new XElement("Title", entry.Title),
                             new XElement("Content", new XCData(entry.Content))
                             );

            XWikiEntries.Add(wikiEntry);
            xDoc.Save(file);
        }