public void AddMagazine(int year, Magazine magazine) { var y = Document.Root.Elements() .FirstOrDefault(element => element.Name == "Year" && int.Parse(element.Value) == year); if (y != null) { var magazineNode = new XElement("Magazine", new XAttribute("name", magazine.Name), new XAttribute("month", magazine.ReleaseMonth)); foreach (var article in magazine.Articles) { magazineNode.Add(new XElement("Article", new XAttribute("title", article.Title), new XAttribute("text", article.Text), new XAttribute("author", article.Author))); } y.Add(magazineNode); Document.Save(Location); } }
public bool ContainsMagazine(int year, Magazine magazine) { return(GetMagazine(year, magazine.Name, magazine.ReleaseMonth) != null); }