Beispiel #1
0
        public HttpResponseMessage PostSort(ContentSortOrder sorted)
        {
            if (sorted == null)
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound));
            }

            //if there's nothing to sort just return ok
            if (sorted.IdSortOrder.Length == 0)
            {
                return(Request.CreateResponse(HttpStatusCode.OK));
            }

            var mediaService = base.ApplicationContext.Services.MediaService;
            var sortedMedia  = new List <IMedia>();

            try
            {
                sortedMedia.AddRange(sorted.IdSortOrder.Select(mediaService.GetById));

                // Save Media with new sort order and update content xml in db accordingly
                if (mediaService.Sort(sortedMedia) == false)
                {
                    LogHelper.Warn <MediaController>("Media sorting failed, this was probably caused by an event being cancelled");
                    return(Request.CreateValidationErrorResponse("Media sorting failed, this was probably caused by an event being cancelled"));
                }
                return(Request.CreateResponse(HttpStatusCode.OK));
            }
            catch (Exception ex)
            {
                LogHelper.Error <MediaController>("Could not update media sort order", ex);
                throw;
            }
        }
Beispiel #2
0
        public HttpResponseMessage PostSort(ContentSortOrder sorted)
        {
            if (sorted == null)
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound));
            }

            //if there's nothing to sort just return ok
            if (sorted.IdSortOrder.Length == 0)
            {
                return(Request.CreateResponse(HttpStatusCode.OK));
            }

            try
            {
                var contentService = Services.ContentService;

                // content service GetByIds does order the content items based on the order of Ids passed in
                var content = contentService.GetByIds(sorted.IdSortOrder);

                // Save content with new sort order and update content xml in db accordingly
                if (contentService.Sort(content) == false)
                {
                    LogHelper.Warn <ContentController>("Content sorting failed, this was probably caused by an event being cancelled");
                    return(Request.CreateValidationErrorResponse("Content sorting failed, this was probably caused by an event being cancelled"));
                }
                return(Request.CreateResponse(HttpStatusCode.OK));
            }
            catch (Exception ex)
            {
                LogHelper.Error <ContentController>("Could not update content sort order", ex);
                throw;
            }
        }
Beispiel #3
0
        protected HttpResponseMessage PerformSort(ContentSortOrder sorted)
        {
            if (sorted == null)
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound));
            }

            //if there's nothing to sort just return ok
            if (sorted.IdSortOrder.Length == 0)
            {
                return(Request.CreateResponse(HttpStatusCode.OK));
            }

            return(null);
        }
    /// <summary>
    ///     Change the sort order for media
    /// </summary>
    /// <param name="sorted"></param>
    /// <returns></returns>
    public async Task <IActionResult> PostSort(ContentSortOrder sorted)
    {
        if (sorted == null)
        {
            return(NotFound());
        }

        //if there's nothing to sort just return ok
        if (sorted.IdSortOrder?.Length == 0)
        {
            return(Ok());
        }

        // Authorize...
        var requirement = new MediaPermissionsResourceRequirement();
        var resource    = new MediaPermissionsResource(sorted.ParentId);
        AuthorizationResult authorizationResult =
            await _authorizationService.AuthorizeAsync(User, resource, requirement);

        if (!authorizationResult.Succeeded)
        {
            return(Forbid());
        }

        var sortedMedia = new List <IMedia>();

        try
        {
            sortedMedia.AddRange(sorted.IdSortOrder?.Select(_mediaService.GetById).WhereNotNull() ??
                                 Enumerable.Empty <IMedia>());

            // Save Media with new sort order and update content xml in db accordingly
            if (_mediaService.Sort(sortedMedia) == false)
            {
                _logger.LogWarning("Media sorting failed, this was probably caused by an event being cancelled");
                return(ValidationProblem("Media sorting failed, this was probably caused by an event being cancelled"));
            }

            return(Ok());
        }
        catch (Exception ex)
        {
            _logger.LogError(ex, "Could not update media sort order");
            throw;
        }
    }
Beispiel #5
0
        /// <summary>
        /// Change the sort order for media
        /// </summary>
        /// <param name="sorted"></param>
        /// <returns></returns>
        public HttpResponseMessage PostSort(ContentSortOrder sorted)
        {
            if (sorted == null)
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound));
            }

            //if there's nothing to sort just return ok
            if (sorted.IdSortOrder.Length == 0)
            {
                return(Request.CreateResponse(HttpStatusCode.OK));
            }

            if (!Security.UserHasAppAccess(global::Umbraco.Core.Constants.Applications.Media, UmbracoUser))
            {
                return(Request.CreateErrorResponse(HttpStatusCode.Unauthorized, "User has no access to this application"));
            }

            var mediaService = base.ApplicationContext.Services.MediaService;
            var sortedMedia  = new List <IMedia>();

            try
            {
                sortedMedia.AddRange(sorted.IdSortOrder.Select(mediaService.GetById));

                // Save Media with new sort order and update content xml in db accordingly
                if (!mediaService.Sort(sortedMedia))
                {
                    LogHelper.Warn <MediaController>("Media sorting failed, this was probably caused by an event being cancelled");
                    return(Request.CreateErrorResponse(HttpStatusCode.Forbidden, "Media sorting failed, this was probably caused by an event being cancelled"));
                }
                return(Request.CreateResponse(HttpStatusCode.OK));
            }
            catch (Exception ex)
            {
                LogHelper.Error <MediaController>("Could not update media sort order", ex);
                throw;
            }
        }