public async Task <IHttpActionResult> PostHomePageByUriAsync(string uri, [FromBody] string homePageUri, CancellationToken cancellationToken) { var portal = await _portalManager.FindByUriAsync(uri, cancellationToken); await ApiSecurity.AuthorizeAsync(portal, AccessPermission.CanEdit, cancellationToken); ValidationResult validationResult; if (homePageUri == null) { validationResult = await _portalManager.SetHomePageAsync(portal, null, cancellationToken); } else { var masterPage = await _portalManager.GetPageByUriAsync(portal, homePageUri, cancellationToken); if (masterPage == null) { return(BadRequest(string.Format(PortalApiResources.PageNotFound, uri))); } validationResult = await _portalManager.SetHomePageAsync(portal, masterPage, cancellationToken); } if (!validationResult.Succeeded) { return(this.ValidationContent(validationResult)); } return(Ok()); }
public async Task <IHttpActionResult> GetByUriAsync(string portalUri, string pageUri, PageField fields, CancellationToken cancellationToken) { var portal = await _portalManager.FindByUriAsync(portalUri, cancellationToken); await ApiSecurity.AuthorizeAsync(portal, AccessPermission.CanView, cancellationToken); var page = await _portalManager.GetPageByUriAsync(portal, pageUri, fields, cancellationToken); if (page == null) { return(NotFound()); } return(Ok(ModelMapper.ToPageDto(page))); }
/// <summary> /// Validates the specified <paramref name="page" /> as an asynchronous operation. /// </summary> /// <param name="manager">The <see cref="PortalManager" /> that can be used to retrieve user properties.</param> /// <param name="portal">The portal which owns the page.</param> /// <param name="page">The page to validate.</param> /// <param name="cancellationToken">The <see cref="CancellationToken" /> used to propagate notifications that the operation should be canceled.</param> /// <returns> /// The <see cref="Task" /> that represents the asynchronous operation, containing the <see cref="ValidationResult" /> of the validation operation. /// </returns> public virtual async Task <ValidationResult> ValidatePageAsync(PortalManager manager, PortalItem portal, PageItem page, CancellationToken cancellationToken) { if (manager == null) { throw new ArgumentNullException(nameof(manager)); } if (portal == null) { throw new ArgumentNullException(nameof(portal)); } if (page == null) { throw new ArgumentNullException(nameof(page)); } var otherPage = await manager.GetPageByUriAsync(portal, page.Uri, cancellationToken); if (otherPage == null || otherPage.Id == page.Id || !string.Equals(otherPage.Uri, page.Uri, StringComparison.Ordinal)) { return(ValidationResult.Success); } return(ValidationResult.Failed(string.Format(CultureInfo.CurrentCulture, PortalResources.DuplicatedPageUri, page.Uri))); }