/// <summary> /// Want to add a new review? Fill an instance of ReviewModel, and put it here /// </summary> /// <param name="Review">New review to add to Sitecore</param> /// <returns>Sitecore Item that was added</returns> /// public Item Add(ReviewModel Review) { try { using (new SecurityDisabler()) { Item newReview; AssistiveToolsSearchResultsPageItem searchPage = MainsectionItem.GetHomePageItem().GetToolsPage().GetAssistiveToolsLandingPage().GetSearchPage(); newReview = GetReviewIfAlreadyExists(Review.CommonSenseMediaID, searchPage); if (newReview == null) { TemplateItem reviewTemplate = Sitecore.Configuration.Factory.GetDatabase("master").GetTemplate(AssistiveToolsReviewPageItem.TemplateId); newReview = Get(searchPage.ID.ToString()).Add(Review.Title, reviewTemplate); } newReview.Editing.BeginEdit(); newReview = Map(newReview, Review); newReview.Editing.EndEdit(); // publish CommonSenseImportHelper.PublishItem(newReview, Sitecore.Configuration.Factory.GetDatabase("master")); CommonSenseImportHelper.PublishItem(newReview, Sitecore.Configuration.Factory.GetDatabase("web")); return newReview; } } catch(Exception e) { return null; } }
/// <summary> /// Want to add a new review? Fill an instance of ReviewModel, and put it here /// </summary> /// <param name="Review">New review to add to Sitecore</param> /// <returns>Sitecore Item that was added</returns> /// public Item Add(ReviewModel Review) { try { using (new SecurityDisabler()) { Item newReview; AssistiveToolsSearchResultsPageItem searchPage = MainsectionItem.GetHomePageItem().GetToolsPage().GetAssistiveToolsLandingPage().GetSearchPage(); newReview = GetReviewIfAlreadyExists(Review.CommonSenseMediaID, searchPage); if (newReview == null) { TemplateItem reviewTemplate = Sitecore.Configuration.Factory.GetDatabase("master").GetTemplate(AssistiveToolsReviewPageItem.TemplateId); newReview = Get(searchPage.ID.ToString()).Add(Review.Title, reviewTemplate); } newReview.Editing.BeginEdit(); newReview = Map(newReview, Review); newReview.Editing.EndEdit(); // publish CommonSenseImportHelper.PublishItem(newReview, Sitecore.Configuration.Factory.GetDatabase("master")); CommonSenseImportHelper.PublishItem(newReview, Sitecore.Configuration.Factory.GetDatabase("web")); return(newReview); } } catch (Exception e) { return(null); } }
/// <summary> /// Updates the desired Review /// </summary> /// <param name="Review">ReviewModel instance to update</param> /// <returns>Updated Review</returns> public Item Update(ReviewModel Review) { Item updateReview = Get(CommonSenseImportHelper.Instance.Settings.ReviewsContainer); updateReview.Editing.BeginEdit(); updateReview = Map(updateReview, Review); updateReview.Editing.EndEdit(); return updateReview; }
/// <summary> /// Maps the ReviewModel to a Sitecore Item /// </summary> /// <param name="mappedReview">Destination Sitecore Item to map</param> /// <param name="Review">Values to map</param> /// <returns>Updated Sitecore item</returns> private Item Map(Item mappedReview, ReviewModel Review) { try { // Single-line text if (mappedReview["title"] != null && !string.IsNullOrEmpty(Review.Title)) { mappedReview["title"] = Review.Title.Trim(); } if (mappedReview["summary"] != null && Review.Summary != null) { mappedReview["summary"] = Review.Summary.Trim(); } if (mappedReview["description"] != null && Review.Description != null) { mappedReview["description"] = Review.Description.Trim(); } if (mappedReview["what parents need to know"] != null && Review.ParentsNeedToKnow != null) { mappedReview["what parents need to know"] = Review.ParentsNeedToKnow.Trim(); } if (mappedReview["what kids can learn"] != null && Review.WhatKidsCanLearn != null) { mappedReview["what kids can learn"] = Review.WhatKidsCanLearn.Trim(); } if (mappedReview["any good"] != null && !string.IsNullOrEmpty(Review.AnyGood)) { mappedReview["any good"] = Review.AnyGood.Trim(); } if (mappedReview["target grade"] != null && !string.IsNullOrEmpty(Review.TargetGrade)) { mappedReview["target grade"] = Review.TargetGrade.Trim(); } if (mappedReview["on grade"] != null && !string.IsNullOrEmpty(Review.OnGrade)) { mappedReview["on grade"] = Review.OnGrade.Trim(); } if (mappedReview["off grade"] != null && !string.IsNullOrEmpty(Review.OffGrade)) { mappedReview["off grade"] = Review.OffGrade.Trim(); } if (mappedReview["apple app store id"] != null && !string.IsNullOrEmpty(Review.AppleAppStoreID)) { mappedReview["apple app store id"] = Review.AppleAppStoreID.Trim(); } if (mappedReview["google play store id"] != null && !string.IsNullOrEmpty(Review.GooglePlayStoreID)) { mappedReview["google play store id"] = Review.GooglePlayStoreID.Trim(); } if (mappedReview["csm id"] != null && !string.IsNullOrEmpty(Review.CommonSenseMediaID)) { mappedReview["csm id"] = Review.CommonSenseMediaID.Trim(); } if (mappedReview["external link"] != null && !string.IsNullOrEmpty(Review.ExternalLink)) { mappedReview["external link"] = "<link text=\"\" linktype=\"external\" url=\"" + Review.ExternalLink + "\" target=\"\" />"; } if (mappedReview["price"] != null && !string.IsNullOrEmpty(Review.Price)) { mappedReview["price"] = Review.Price.Trim(); } if (mappedReview["how parents can help"] != null && Review.HowParentsCanHelp != null) { mappedReview["how parents can help"] = Review.HowParentsCanHelp.Trim(); } if (mappedReview["learning"] != null && Review.LearningRank != null) { mappedReview["learning"] = Review.LearningRank.Trim(); } if (mappedReview["publish date"] != null && Review.Published != null) { mappedReview["publish date"] = Review.Published.Trim(); } if (mappedReview["quality"] != null && Review.QualityRank != null) { mappedReview["quality"] = Review.QualityRank.Trim(); } if (mappedReview["screenshots"] != null && Review.Screenshots != null) { mappedReview["screenshots"] = CommonSenseImportHelper.addMedia(Review.Screenshots).Trim(); } if (mappedReview["platforms"] != null && Review.Platforms != null) { mappedReview["platforms"] = CommonSenseImportHelper.MatchCSV(Review.Platforms, "{042EBC5C-CCA0-4758-823D-A07213A72434}").Trim(); } if (mappedReview["skills"] != null && Review.Skills != null) { mappedReview["skills"] = CommonSenseImportHelper.MatchCSV(Review.Skills, MainsectionItem.GetGlobals().GetSkillsFolder().ID.ToString()).Trim(); } if (mappedReview["subjects"] != null && Review.Subjects != null) { mappedReview["subjects"] = CommonSenseImportHelper.MatchCSV(Review.Subjects, "{11AAE042-9BFA-43C4-A971-0AF140108921}").Trim(); } if (mappedReview["issues"] != null && Review.Issues != null) { mappedReview["issues"] = CommonSenseImportHelper.MatchCSVIssues(Review.Issues, "{5CDC7D81-19CA-4CF6-8C58-A4D013823A05}").Trim(); } if (mappedReview["genre"] != null && Review.Genres != null) { mappedReview["genre"] = CommonSenseImportHelper.MatchCSV(Review.Genres, "{97908446-B312-4183-915E-2E43BA5A7693}").Trim(); } if (mappedReview["thumbnail image"] != null && Review.Thumbnail != null) { MediaItem temp = CommonSenseImportHelper.addMedia(Review.Thumbnail); if(temp != null) mappedReview["thumbnail image"] = "<image mediaid=\"" + temp.ID.ToString() + "\" mediapath=\"" + temp.MediaPath + "\" src=\"" + temp.FilePath + "\" />"; } if (mappedReview["type"] != null && Review.Type != null) { mappedReview["type"] = CommonSenseImportHelper.MatchCSV(Review.Type, "{88226E2B-BAFE-44E9-8EEE-95525458EA14}").Trim(); } if (mappedReview["category"] != null && Review.Category != null) { mappedReview["category"] = CommonSenseImportHelper.GetCategory(Review.Category).Trim(); } } catch (Exception e) { return mappedReview; } //// Links //mappedReview["telligent id"] = Review.TelligentID; //// Numbers //mappedReview["quality"] = Review.QualityRank; return mappedReview; }
/// <summary> /// Maps the ReviewModel to a Sitecore Item /// </summary> /// <param name="mappedReview">Destination Sitecore Item to map</param> /// <param name="Review">Values to map</param> /// <returns>Updated Sitecore item</returns> private Item Map(Item mappedReview, ReviewModel Review) { try { // Single-line text if (mappedReview["title"] != null && !string.IsNullOrEmpty(Review.Title)) { mappedReview["title"] = Review.Title.Trim(); } if (mappedReview["summary"] != null && Review.Summary != null) { mappedReview["summary"] = Review.Summary.Trim(); } if (mappedReview["description"] != null && Review.Description != null) { mappedReview["description"] = Review.Description.Trim(); } if (mappedReview["what parents need to know"] != null && Review.ParentsNeedToKnow != null) { mappedReview["what parents need to know"] = Review.ParentsNeedToKnow.Trim(); } if (mappedReview["what kids can learn"] != null && Review.WhatKidsCanLearn != null) { mappedReview["what kids can learn"] = Review.WhatKidsCanLearn.Trim(); } if (mappedReview["any good"] != null && !string.IsNullOrEmpty(Review.AnyGood)) { mappedReview["any good"] = Review.AnyGood.Trim(); } if (mappedReview["target grade"] != null && !string.IsNullOrEmpty(Review.TargetGrade)) { mappedReview["target grade"] = Review.TargetGrade.Trim(); } if (mappedReview["on grade"] != null && !string.IsNullOrEmpty(Review.OnGrade)) { mappedReview["on grade"] = Review.OnGrade.Trim(); } if (mappedReview["off grade"] != null && !string.IsNullOrEmpty(Review.OffGrade)) { mappedReview["off grade"] = Review.OffGrade.Trim(); } if (mappedReview["apple app store id"] != null && !string.IsNullOrEmpty(Review.AppleAppStoreID)) { mappedReview["apple app store id"] = Review.AppleAppStoreID.Trim(); } if (mappedReview["google play store id"] != null && !string.IsNullOrEmpty(Review.GooglePlayStoreID)) { mappedReview["google play store id"] = Review.GooglePlayStoreID.Trim(); } if (mappedReview["csm id"] != null && !string.IsNullOrEmpty(Review.CommonSenseMediaID)) { mappedReview["csm id"] = Review.CommonSenseMediaID.Trim(); } if (mappedReview["external link"] != null && !string.IsNullOrEmpty(Review.ExternalLink)) { mappedReview["external link"] = "<link text=\"\" linktype=\"external\" url=\"" + Review.ExternalLink + "\" target=\"\" />"; } if (mappedReview["price"] != null && !string.IsNullOrEmpty(Review.Price)) { mappedReview["price"] = Review.Price.Trim(); } if (mappedReview["how parents can help"] != null && Review.HowParentsCanHelp != null) { mappedReview["how parents can help"] = Review.HowParentsCanHelp.Trim(); } if (mappedReview["learning"] != null && Review.LearningRank != null) { mappedReview["learning"] = Review.LearningRank.Trim(); } if (mappedReview["publish date"] != null && Review.Published != null) { mappedReview["publish date"] = Review.Published.Trim(); } if (mappedReview["quality"] != null && Review.QualityRank != null) { mappedReview["quality"] = Review.QualityRank.Trim(); } if (mappedReview["screenshots"] != null && Review.Screenshots != null) { mappedReview["screenshots"] = CommonSenseImportHelper.addMedia(Review.Screenshots).Trim(); } if (mappedReview["platforms"] != null && Review.Platforms != null) { mappedReview["platforms"] = CommonSenseImportHelper.MatchCSV(Review.Platforms, "{042EBC5C-CCA0-4758-823D-A07213A72434}").Trim(); } if (mappedReview["skills"] != null && Review.Skills != null) { mappedReview["skills"] = CommonSenseImportHelper.MatchCSV(Review.Skills, MainsectionItem.GetGlobals().GetSkillsFolder().ID.ToString()).Trim(); } if (mappedReview["subjects"] != null && Review.Subjects != null) { mappedReview["subjects"] = CommonSenseImportHelper.MatchCSV(Review.Subjects, "{11AAE042-9BFA-43C4-A971-0AF140108921}").Trim(); } if (mappedReview["issues"] != null && Review.Issues != null) { mappedReview["issues"] = CommonSenseImportHelper.MatchCSVIssues(Review.Issues, "{5CDC7D81-19CA-4CF6-8C58-A4D013823A05}").Trim(); } if (mappedReview["genre"] != null && Review.Genres != null) { mappedReview["genre"] = CommonSenseImportHelper.MatchCSV(Review.Genres, "{97908446-B312-4183-915E-2E43BA5A7693}").Trim(); } if (mappedReview["thumbnail image"] != null && Review.Thumbnail != null) { MediaItem temp = CommonSenseImportHelper.addMedia(Review.Thumbnail); if (temp != null) { mappedReview["thumbnail image"] = "<image mediaid=\"" + temp.ID.ToString() + "\" mediapath=\"" + temp.MediaPath + "\" src=\"" + temp.FilePath + "\" />"; } } if (mappedReview["type"] != null && Review.Type != null) { mappedReview["type"] = CommonSenseImportHelper.MatchCSV(Review.Type, "{88226E2B-BAFE-44E9-8EEE-95525458EA14}").Trim(); } if (mappedReview["category"] != null && Review.Category != null) { mappedReview["category"] = CommonSenseImportHelper.GetCategory(Review.Category).Trim(); } } catch (Exception e) { return(mappedReview); } //// Links //mappedReview["telligent id"] = Review.TelligentID; //// Numbers //mappedReview["quality"] = Review.QualityRank; return(mappedReview); }
public int ImportCategory(XmlNodeList nodes) { ReviewManager reviewManager = new ReviewManager(); int count = 0; foreach (XmlNode x in nodes) { ReviewModel newItem = new ReviewModel(); try { XmlNodeList temp; if (x["id"] != null) newItem.CommonSenseMediaID = x["id"].InnerText; if (x["link"] != null) newItem.ExternalLink = x["link"].GetAttribute("href"); if (x["category"] != null) newItem.Type = x["category"].GetAttribute("term"); if (x["published"] != null) newItem.Published = Sitecore.DateUtil.ToIsoDate(DateTime.Parse(x["published"].InnerText)); if (x["title"] != null) newItem.Title = x["title"].InnerText; if (x["summary"] != null) newItem.Summary = x["summary"].InnerText; if (x["csm:product"] != null) { if (x["csm:product"]["csm:references"] != null) { temp = x["csm:product"]["csm:references"].ChildNodes; foreach (XmlNode t in temp) { if (t.Attributes["type"].InnerText == "itunes") { newItem.AppleAppStoreID = t.InnerText; } else if (t.Attributes["type"].InnerText == "googleplay") { newItem.GooglePlayStoreID = t.InnerText; } } } if (x["csm:product"]["csm:images"] != null) { temp = x["csm:product"]["csm:images"].ChildNodes; List<ReviewImageModel> images = new List<ReviewImageModel>(); foreach (XmlNode t in temp) { if (t.Attributes["type"].InnerText == "screenshot") { ReviewImageModel image = new ReviewImageModel(); image.URL = t.InnerText; image.Name = newItem.Title + "-screenshot-" + (images.Count + 1).ToString(); image.AltText = "Screenshot"; images.Add(image); } else if (t.Attributes["type"].InnerText == "product") { ReviewImageModel image = new ReviewImageModel(); image.URL = t.InnerText; image.Name = newItem.Title + "-screenshot-" + (images.Count + 1).ToString(); image.AltText = "Screenshot"; newItem.Thumbnail = image; } } newItem.Screenshots = images; } if (x["csm:product"]["csm:platforms"] != null) { temp = x["csm:product"]["csm:platforms"].ChildNodes; foreach (XmlNode t in temp) { newItem.Platforms += t.InnerText + ","; } } if (x["csm:product"]["csm:prices"] != null && x["csm:product"]["csm:prices"]["csm:price"] != null) newItem.Price = x["csm:product"]["csm:prices"]["csm:price"].InnerText; if (x["csm:product"]["csm:genre"] != null) newItem.Genres = x["csm:product"]["csm:genre"].InnerText; } if (x["csm:review"] != null) { newItem.QualityRank = x["csm:review"].GetAttribute("star_rating"); if (x["csm:review"]["csm:slider"] != null) { newItem.TargetGrade = ResolveGrade(x["csm:review"]["csm:slider"].GetAttribute("target_age")); newItem.OffGrade = ResolveGrade(x["csm:review"]["csm:slider"].GetAttribute("off_age")); newItem.OnGrade = ResolveGrade(x["csm:review"]["csm:slider"].GetAttribute("on_age")); } if (x["csm:review"]["csm:parents_need_to_know"] != null) newItem.ParentsNeedToKnow = x["csm:review"]["csm:parents_need_to_know"].InnerText; if (x["csm:review"]["csm:description"] != null) newItem.Description = x["csm:review"]["csm:description"].InnerText; if (x["csm:review"]["csm:any_good"] != null) newItem.AnyGood = x["csm:review"]["csm:any_good"].InnerText; if (x["csm:review"]["csm:learning_rating"] != null) { newItem.LearningRank = x["csm:review"]["csm:learning_rating"].GetAttribute("value"); if (x["csm:review"]["csm:learning_rating"]["csm:what_kids_can_learn"] != null) newItem.WhatKidsCanLearn = x["csm:review"]["csm:learning_rating"]["csm:what_kids_can_learn"].InnerText; if (x["csm:review"]["csm:learning_rating"]["csm:how_parents_help"] != null) newItem.HowParentsCanHelp = x["csm:review"]["csm:learning_rating"]["csm:how_parents_help"].InnerText; if (x["csm:review"]["csm:learning_rating"]["csm:subjects"] != null) { temp = x["csm:review"]["csm:learning_rating"]["csm:subjects"].ChildNodes; foreach (XmlNode t in temp) { newItem.Subjects += t.Attributes["name"].InnerText + ","; } } if (x["csm:review"]["csm:learning_rating"]["csm:skills"] != null) { temp = x["csm:review"]["csm:learning_rating"]["csm:skills"].ChildNodes; foreach (XmlNode t in temp) { newItem.Skills += t.Attributes["name"].InnerText + ","; } } } if (x["csm:review"]["csm:special_needs"] != null) { temp = x["csm:review"]["csm:special_needs"].ChildNodes; foreach (XmlNode t in temp) { newItem.Issues += t.Attributes["name"].InnerText + ","; } newItem.Category = x["csm:review"]["csm:special_needs"].GetAttribute("assistive"); } } } catch(Exception e) { Log += e.Message+"<br><br><b>"; } try { reviewManager.Add(newItem); count++; } catch { } } return count; }