Objects in Cartella are manipulated via their type-specific Manager objects.

For instance, use the ICommentManager to create, update, or delete comments.

Object manipulation is possible only when the SiteManager contains an authenticated user context; it is the user context that allows the object to be manipulated.

Creating a new object

Object Creation across all Object Managers follows the same pattern. A specific Object Manager will provide a constructor method with the exact parameters needed to construct the object.

CopyC#
////////////////////////////////////////////////////////////////////////////////
// Creating a Comment Object with Manager-specific approach
////////////////////////////////////////////////////////////////////////////////

ICommentManager commentManager = siteManager.GetManager<ICommentManager>();

IBlogPost blogToCommentTo = siteManager.SelectSingleObject<BlogPost>(entityID) as IBlogPost;

//Create object with Manager-specific syntax
IComment comment1 = commentManager.CreateComment(blogToCommentTo, null,
    "Test Comment Title", "", true, "Test Comment Content");
CopyC#
////////////////////////////////////////////////////////////////////////////////
// Creating a Comment Object using inheritance from the CartellaObjectManager
////////////////////////////////////////////////////////////////////////////////

ICommentManager commentManager = siteManager.GetManager<ICommentManager>();

FieldCollection fields = new FieldCollection();

// Add the ID_Entity field to the collection
fields.Add(new Field(new FieldDefinition("ID_Entity", false, false), entityID));

// Add the ID_Parent field to the collection
if (parentID != null)
    fields.Add(new Field(new FieldDefinition("ID_Parent", true, false), parentID));

// Add the Name field to the collection
if (name != null)
    fields.Add(new Field(new FieldDefinition("Name", true, false), name));

// Add the Email field to the collection
fields.Add(new Field(new FieldDefinition("Email", false, false), email));

// Add the Approved field to the collection
string approvedString = approved ? "1" : "0";
fields.Add(new Field(new FieldDefinition("Approved", false, false), approvedString));

// Add the "Comment" field to the collection
if (comment != null)
    fields.Add(new Field(new FieldDefinition("Comment", true, false), comment));

IBlogPost blogToCommentTo = siteManager.SelectSingleObject<BlogPost>(entityID) as IBlogPost;            

//Create the object with Manager generic syntax
IComment comment2 = commentManager.Create<Comment>(fields, blog.OwnerFolio);
Note
Use of the specific Object Manager is recommended. Objects created in this way are less likely to generate errors due to missing or incorrect field information.

Updating an existing object

Cartella objects are strongly typed to provide easy manipulation of the underlying data.

For objects implementing the ICartellaObject interface, setting properties will result in an object update and the database transaction associated with that update.

To update multiple fields with a single database transaction, use the StartUpdate method. Deferred execution is provided by the IDisposable interface.

CopyC#
////////////////////////////////////////////////////////////////////////////////
// Update fields of a BlogPost field by field, using automated properties
////////////////////////////////////////////////////////////////////////////////    
IBlogPost blog = blogManager.SelectSingleBlog(blogId);

//update blog name
blog.Name = "New Blog Name";
blog.Description = "New Blog Content";
blog.OwnerModule = newFolioModule;
CopyC#
////////////////////////////////////////////////////////////////////////////////
// Update fields of a BlogPost together
////////////////////////////////////////////////////////////////////////////////    
IBlogPost blog = blogManager.SelectSingleBlog(blogId);

using(blog.StartUpdate()) //StartUpdate method returns a IDisposable object
{

    blog.Name = "New Blog Name";
    blog.Description = "New Blog Content";
    blog.OwnerModule = newFolioModule;        

} //database transaction is carried out upon disposing the returning object
Note
Using the StartUpdate method is recommended as it requires far fewer calls to the SQL server when multiple updates are needed.

Deleting/Removing Objects

There are two types of deletion action in Cartella API. Mark for Deletion vs. Permanent Deletion.

Mark for Deletion tags the object as deleted. The Object may be restored to normal by turning off the Deleted tag, or it may be purged by removing the record from the database.

Permanent Deletion removes the record from database. This action is not recoverable.

Invoke "Mark for Deletion" by calling Remove, and "Permenant Deletion" by calling Delete.

Two types of objects support Remove: IEntity (including folios and all folio item types), and IUser. For all other types, deletions are permanent

 

As when creating objects, either use the Manager's type-specific methods or use the Delete<T> method on Manager inherited from the ICartellaObjectManager interface. The DeleteObject<T> method may be used on the SiteManager directly.

CopyC#
////////////////////////////////////////////////////////////////////////////////
// Deleting a BlogPost (IEntity) in various ways
////////////////////////////////////////////////////////////////////////////////    
IBlogPost blog = blogManager.SelectSingleBlog(blogId);

//Removal with Manager object-specific method
blogManager.RemoveBlog(ref blog);

//Removal with ICartellaObjectManager inherited method
blogManager.Delete<IBlogPost>(ref blog);

//Removal with ICartellaObjectManager inherited - Permenant delete
blogManager.Delete<IBlogPost>(ref blog, true); 

//Removal with SiteManager
siteManager.DeleteObject<IBlogPost>(ref blog);

//Restore a removed blog
blogManager.Restore<IBlogPost>(ref blog);

//Purge a removed blog
blogManager.Purge<IBlogPost>(ref blog);

See Also

Reference

ICartellaObjectManager