/// <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; } }
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 contentService = Services.ContentService; var sortedContent = new List<IContent>(); try { sortedContent.AddRange(Services.ContentService.GetByIds(sorted.IdSortOrder)); // Save content with new sort order and update content xml in db accordingly if (contentService.Sort(sortedContent) == false) { LogHelper.Warn<MediaController>("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<MediaController>("Could not update content sort order", ex); throw; } }