예제 #1
0
        public async Task <IHttpActionResult> PostReferencesAsync(string portalUri, string pageUri, [FromBody] IEnumerable <ReferenceItemDto> model, CancellationToken cancellationToken)
        {
            if (model == null || !ModelState.IsValid)
            {
                return(BadRequest());
            }
            var portal = await _portalManager.FindByUriAsync(portalUri, cancellationToken);

            await ApiSecurity.AuthorizeAsync(portal, AccessPermission.CanEdit, cancellationToken);

            var page = await _portalManager.GetPageByUriAsync(portal, pageUri, cancellationToken);

            if (page == null)
            {
                return(NotFound());
            }
            var validationResult = await _portalManager.SetPageReferencesAsync(portal, page, model.Select(r => ReferenceItem.Create(r.Type, r.Uri)), cancellationToken);

            if (!validationResult.Succeeded)
            {
                return(this.ValidationContent(validationResult));
            }
            return(Ok(ModelMapper.ToPageDto(page)));
        }