public HttpResponseMessage SavePage(DTO.PageDetails page) { var apiResponse = new DTO.ApiResponse <DTO.SavePageResponse>(); apiResponse.CustomObject = new DTO.SavePageResponse(); try { //Validation: //Tab name is required //Tab name is invalid string invalidType; if (!DotNetNuke.Entities.Tabs.TabController.IsValidTabName(page.Name, out invalidType)) { switch (invalidType) { case "EmptyTabName": apiResponse.Message = "Page name is required."; break; case "InvalidTabName": apiResponse.Message = "Page name is invalid."; break; } return(Request.CreateResponse(HttpStatusCode.OK, apiResponse)); } var tc = new DotNetNuke.Entities.Tabs.TabController(); var dnnTab = page.Id == -1 ? new DotNetNuke.Entities.Tabs.TabInfo() : tc.GetTab(page.Id, PortalSettings.PortalId); if (dnnTab != null) { dnnTab.TabName = page.Name.Trim(); if (!string.IsNullOrWhiteSpace(page.Title)) { dnnTab.Title = page.Title.Trim(); } if (!string.IsNullOrWhiteSpace(page.Description)) { dnnTab.Description = page.Description.Trim(); } dnnTab.IsVisible = page.Visible; dnnTab.DisableLink = page.Disabled; dnnTab.IsSecure = page.Secure; if (!string.IsNullOrWhiteSpace(page.Theme)) { dnnTab.SkinSrc = page.Theme != "-1" ? page.Theme : string.Empty; } if (!string.IsNullOrWhiteSpace(page.Container)) { dnnTab.ContainerSrc = page.Container != "-1" ? page.Container : string.Empty; } if (page.Id == -1) { var positionTabID = int.Parse(page.Position); var positionModeInt = int.Parse(page.PositionMode); var parentTab = tc.GetTab(positionTabID, PortalSettings.PortalId); if (page.PositionMode == ((int)DTO.PagePositionMode.ChildOf).ToString()) { if (parentTab != null) { dnnTab.PortalID = parentTab.PortalID; dnnTab.ParentId = parentTab.TabID; dnnTab.Level = parentTab.Level + 1; } page.Id = tc.AddTab(dnnTab); } else { dnnTab.PortalID = PortalSettings.PortalId; switch (positionModeInt) { case (int)DTO.PagePositionMode.After: dnnTab.PortalID = parentTab.PortalID; dnnTab.ParentId = parentTab.ParentId; dnnTab.Level = parentTab.Level; page.Id = tc.AddTabAfter(dnnTab, int.Parse(page.Position)); break; case (int)DTO.PagePositionMode.Before: dnnTab.PortalID = parentTab.PortalID; dnnTab.ParentId = parentTab.ParentId; dnnTab.Level = parentTab.Level; page.Id = tc.AddTabBefore(dnnTab, int.Parse(page.Position)); break; default: page.Id = tc.AddTab(dnnTab); break; } } apiResponse.CustomObject.Redirect = true; apiResponse.CustomObject.Url = DotNetNuke.Common.Globals.NavigateURL(page.Id); } else { if (page.PositionMode == ((int)DTO.PagePositionMode.ChildOf).ToString()) { var positionTabID = int.Parse(page.Position); if (positionTabID == -1) { dnnTab.PortalID = PortalSettings.PortalId; dnnTab.ParentId = -1; dnnTab.Level = 0; } else { var parentTab = tc.GetTab(positionTabID, PortalSettings.PortalId); if (parentTab != null) { dnnTab.PortalID = parentTab.PortalID; dnnTab.ParentId = parentTab.TabID; dnnTab.Level = parentTab.Level + 1; } } apiResponse.CustomObject.Redirect = true; apiResponse.CustomObject.Url = DotNetNuke.Common.Globals.NavigateURL(page.Id); } if (!string.IsNullOrWhiteSpace(page.Position) && !string.IsNullOrWhiteSpace(page.PositionMode)) { var positionTabID = int.Parse(page.Position); var positionModeInt = int.Parse(page.PositionMode); var parentTab = tc.GetTab(positionTabID, PortalSettings.PortalId); if (parentTab != null) { switch (positionModeInt) { case (int)DTO.PagePositionMode.After: dnnTab.PortalID = parentTab.PortalID; dnnTab.ParentId = parentTab.ParentId; dnnTab.Level = parentTab.Level; tc.UpdateTab(dnnTab); tc.MoveTabAfter(dnnTab, parentTab.TabID); apiResponse.CustomObject.Redirect = true; apiResponse.CustomObject.Url = DotNetNuke.Common.Globals.NavigateURL(page.Id); break; case (int)DTO.PagePositionMode.Before: dnnTab.PortalID = parentTab.PortalID; dnnTab.ParentId = parentTab.ParentId; dnnTab.Level = parentTab.Level; tc.UpdateTab(dnnTab); tc.MoveTabBefore(dnnTab, parentTab.TabID); apiResponse.CustomObject.Redirect = true; apiResponse.CustomObject.Url = DotNetNuke.Common.Globals.NavigateURL(page.Id); break; case (int)DTO.PagePositionMode.ChildOf: tc.UpdateTab(dnnTab); break; } } else { tc.UpdateTab(dnnTab); } } else { tc.UpdateTab(dnnTab); } } apiResponse.Success = true; } } catch (Exception err) { apiResponse.Success = false; apiResponse.Message = err.Message; Exceptions.LogException(err); } return(Request.CreateResponse(HttpStatusCode.OK, apiResponse)); }