Deleting message bodies
Deleting a single message body
To delete a specific message body, you use the NewslettersManager class. The following code deletes a message body with the specified ID through the Native API.
public void DeleteMessageBody(Guid id)
{
NewslettersManager manager = NewslettersManager.GetManager();
if (manager.GetMessageBodies().Where(b => b.Id == id).Count() > 0)
{
manager.DeleteMessageBody(id);
manager.SaveChanges();
}
}
First, you initialize the NewslettersManager. Then, you check whether an item with the specified ID exists. Finally, you delete the message body by calling DeleteMessageBody and save the changes.
Deleting all message bodies
To delete all message bodies, you use the NewslettersManager class. The following code deletes all available message bodies in Sitefinity through the Native API.
public void DeleteMessageBodies()
{
NewslettersManager manager = NewslettersManager.GetManager();
List<MessageBody> messageBodies = manager.GetMessageBodies().ToList();
foreach (var messageBody in messageBodies)
{
manager.DeleteMessageBody(messageBody);
}
manager.SaveChanges();
}
First, you initialize the NewslettersManager. Then, you get all the available message bodies. Then, you iterate the collection deleting the message bodies one by one. Finally, you save the changes.