using System.Net;
using System.Net.Http;
using Umbraco.Web.WebApi;
namespace Example.Controllers
{
///
/// Protectec Backoffice controller - Users must be logged in to call this
/// Url: /umbraco/backoffice/api/bulk/PostPerformBulkUpdate
///
public class BulkController : UmbracoAuthorizedApiController
{
//Add a model to pass in details like ContentType alias, PropertyType alias
//and value to update
public HttpResponseMessage PostPerformBulkUpdate()
{
//Find a ContentType with a specific alias
var contentType = this.Services.ContentTypeService.GetContentType("myAlias");
//Here we get all content items based on the above ContentType
var contentService = this.Services.ContentService;
var contentOfType = contentService.GetContentOfContentType(contentType.Id);
//If you know the Ids of the content items
//var contentItems = contentService.GetByIds(new List {1241, 1242, 1243});
//Iterate the content items based on the "myAlias" ContentType
foreach (var content in contentOfType)
{
//Update the value of a specific property
//(a check could have been done before this to ensure that the property exists and previous value was "X")
content.Properties["myPropertyAlias"].Value = "a different value then before";
//Save and publish the updated content item
var status = contentService.SaveAndPublishWithStatus(content);
}
return Request.CreateResponse(HttpStatusCode.OK);
}
}
}