public void Add_Multi_Pages_For_Exisitng_Shoul_Return_Results() { var rnd = new Random().Next(1000, 10000); var addPagesDto = new BulkPage { BulkPages = "Page_" + rnd, ParentId = -1, Keywords = string.Empty, Tags = string.Empty, IncludeInMenu = true, StartDate = null, EndDate = null, }; Console.WriteLine(@"Add bulk pages request = {0}", JsonConvert.SerializeObject(addPagesDto)); var connector = WebApiTestHelper.LoginHost(); var response = connector.PostJson(AddBulkPagesApi, addPagesDto).Content.ReadAsStringAsync().Result; var result = JsonConvert.DeserializeObject <BulkPageResponseWrapper>(response); Console.WriteLine(@"Add bulk pages ersponse = {0}", response); Assert.AreEqual(0, result.Status); Assert.IsNull(result.Response.Pages.First().ErrorMessage); var response2 = connector.PostJson(VerigyBulkPagesApi, addPagesDto).Content.ReadAsStringAsync().Result; var result2 = JsonConvert.DeserializeObject <BulkPageResponseWrapper>(response2); Console.WriteLine(@"Verify bulk pages ersponse = {0}", response2); Assert.AreEqual(0, int.Parse(result2.Status.ToString())); Assert.IsNotNullOrEmpty(result2.Response.Pages.First().ErrorMessage); }
public HttpResponseMessage SaveBulkPages(BulkPage bulkPage) { if (!_securityService.IsPageAdminUser()) { return(GetForbiddenResponse()); } try { bulkPage.Clean(); var bulkPageResponse = _bulkPagesController.AddBulkPages(bulkPage); return(Request.CreateResponse(HttpStatusCode.OK, new { Status = 0, Response = bulkPageResponse })); } catch (PageValidationException ex) { return(Request.CreateResponse(HttpStatusCode.OK, new { Status = 1, ex.Field, ex.Message })); } }
public BulkPageResponse AddBulkPages(BulkPage page, bool validateOnly) { var portalSettings = PortalController.Instance.GetCurrentPortalSettings(); var portalId = portalSettings.PortalId; var response = new BulkPageResponse(); var parentId = page.ParentId; var rootTab = TabController.Instance.GetTab(parentId, portalId, true); var strValue = page.BulkPages; strValue = strValue.Replace("\r", "\n").Replace("\n\n", "\n").Trim(); string invalidType; if (!TabController.IsValidTabName(strValue, out invalidType)) { throw new BulkPagesException("bulkPages", string.Format(Localization.GetString(invalidType), strValue)); } if (page.StartDate.HasValue && page.EndDate.HasValue && page.StartDate > page.EndDate) { throw new BulkPagesException("endDate", Localization.GetString("StartDateAfterEndDate")); } var pages = strValue.Split('\n'); var tabs = new List <TabInfo>(); foreach (var strLine in pages) { var tab = new TabInfo { TabName = TabNameRegex.Replace(strLine, "${1}"), Level = strLine.LastIndexOf(">", StringComparison.Ordinal) + 1, KeyWords = page.Keywords, StartDate = page.StartDate ?? Null.NullDate, EndDate = page.EndDate ?? Null.NullDate, IsVisible = page.IncludeInMenu }; tab.Terms.AddRange(TermHelper.ToTabTerms(page.Tags, portalId)); tabs.Add(tab); } var currentIndex = -1; var bulkPageItems = new List <BulkPageResponseItem>(); foreach (var oTab in tabs) { currentIndex += 1; try { string errorMessage = null; if (oTab.Level == 0) { oTab.TabID = this.CreateTabFromParent(portalSettings, rootTab, oTab, parentId, validateOnly, out errorMessage); } else if (validateOnly) { errorMessage = string.Empty; } else { var parentTabId = GetParentTabId(tabs, currentIndex, oTab.Level - 1); if (parentTabId != Null.NullInteger) { oTab.TabID = this.CreateTabFromParent(portalSettings, rootTab, oTab, parentTabId, validateOnly, out errorMessage); } } bulkPageItems.Add(ToBulkPageResponseItem(oTab, errorMessage)); } catch (Exception ex) { throw new DotNetNukeException("Unable to process page.", ex, DotNetNukeErrorCode.DeserializePanesFailed); } } response.Pages = bulkPageItems; return(response); }
public static void Clean(this BulkPage input) { input.BulkPages = Clean(input.BulkPages); input.Keywords = Clean(input.Keywords); input.Tags = Clean(input.Tags); }