GetByIds content method
This commit is contained in:
@@ -221,6 +221,19 @@ namespace Umbraco.Core.Services
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="IContent"/> object by Id
|
||||
/// </summary>
|
||||
/// <param name="ids">Ids of the Content to retrieve</param>
|
||||
/// <returns><see cref="IContent"/></returns>
|
||||
internal IEnumerable<IContent> GetByIds(IEnumerable<int> ids)
|
||||
{
|
||||
using (var repository = _repositoryFactory.CreateContentRepository(_uowProvider.GetUnitOfWork()))
|
||||
{
|
||||
return repository.GetAll(ids.ToArray());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="IContent"/> object by its 'UniqueId'
|
||||
/// </summary>
|
||||
|
||||
@@ -10,6 +10,14 @@ function contentResource($q, $http, umbDataFormatter, umbRequestHelper) {
|
||||
return Umbraco.Sys.ServerVariables.contentApiBaseUrl + "GetById?id=" + contentId;
|
||||
}
|
||||
/** internal method to get the api url */
|
||||
function getByIdsUrl(ids) {
|
||||
var idQuery = "";
|
||||
_.each(ids, function(item) {
|
||||
idQuery += "ids=" + item + "&";
|
||||
});
|
||||
return Umbraco.Sys.ServerVariables.contentApiBaseUrl + "GetById?" + idQuery;
|
||||
}
|
||||
/** internal method to get the api url */
|
||||
function getEmptyContentUrl(contentTypeAlias, parentId) {
|
||||
return Umbraco.Sys.ServerVariables.contentApiBaseUrl + "GetEmpty?contentTypeAlias=" + contentTypeAlias + "&parentId=" + parentId;
|
||||
}
|
||||
@@ -46,6 +54,22 @@ function contentResource($q, $http, umbDataFormatter, umbRequestHelper) {
|
||||
|
||||
return deferred.promise;
|
||||
},
|
||||
|
||||
getByIds: function (ids) {
|
||||
|
||||
var deferred = $q.defer();
|
||||
|
||||
//go and get the data
|
||||
$http.get(getByIdsUrl(ids)).
|
||||
success(function (data, status, headers, config) {
|
||||
deferred.resolve(data);
|
||||
}).
|
||||
error(function (data, status, headers, config) {
|
||||
deferred.reject('Failed to retreive data for content ids ' + ids);
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
},
|
||||
|
||||
/** returns an empty content object which can be persistent on the content service
|
||||
requires the parent id and the alias of the content type to base the scaffold on */
|
||||
|
||||
@@ -7,6 +7,7 @@ using System.Web.Http.ModelBinding;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Models.Editors;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Web.Models.ContentEditing;
|
||||
using Umbraco.Web.Models.Mapping;
|
||||
using Umbraco.Web.Mvc;
|
||||
@@ -54,6 +55,13 @@ namespace Umbraco.Web.Editors
|
||||
controllerContext.Configuration.Formatters.Remove(controllerContext.Configuration.Formatters.XmlFormatter);
|
||||
}
|
||||
|
||||
public IEnumerable<ContentItemDisplay> GetByIds([FromUri]int[] ids)
|
||||
{
|
||||
var foundContent = ((ContentService) Services.ContentService).GetByIds(ids);
|
||||
|
||||
return foundContent.Select(x => _contentModelMapper.ToContentItemDisplay(x));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the content json for the content id
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user