private IList<Review> GetReviews(XElement bookXml) { var reviewsCollection = new List<Review>(); var reviewsXml = bookXml.Element("reviews"); if (reviewsXml != null) { foreach (var reviewXElement in reviewsXml.Elements("review")) { var review = new Review(); this.SetAuthor(reviewXElement, review); this.SetDateOfCreation(reviewXElement, review); this.SetContent(reviewXElement, review); reviewsCollection.Add(review); } } return reviewsCollection; }
private void SetDateOfCreation(XElement reviewXElement, Review review) { var dateOfCreationAttribute = reviewXElement.Attribute("date"); var dateOfCreation = dateOfCreationAttribute != null ? DateTime.Parse(dateOfCreationAttribute.Value) : DateTime.Now; review.DateOfCreation = dateOfCreation; }
private void SetContent(XElement reviewXElement, Review review) { var reviewContent = reviewXElement.Value.Trim(); review.Content = reviewContent; }
private void SetAuthor(XElement reviewXElement, Review review) { var authorAttribute = reviewXElement.Attribute("author"); if (authorAttribute != null) { var author = this.GetOrCreateAuthor(authorAttribute.Value); review.Author = author; } }