For this example, we will also create a ProjectsProcedures class. It will provide database communication functions. The Manager knows all procedures. For every object created, it assigns object-specific procedures as delegates to the object.

With procedures, it is not necessary to declare an interface. The procedure will be referenced directly.

Note

Note: FolioItemProcedures is a MSSQL-specific object procedures class.

CopyC#
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using Cartella.Classes;
using Cartella.Interfaces;


namespace Cartella.Classes
{
    public class ProjectsProcedures : FolioItemProcedures
    {
        public ProjectsProcedures(MSSQLUserSpecificDataProceduresBase procBase)
            : base(procBase)
        {
        }

        public override Type BaseObjectType
        {
            get
            {
                return typeof(Project);
            }
        }
    }
}

The new class ProjectsProcedures only needs to implement the FolioItemProcedures base class, and return the BaseObjectType property for the class type it represents (Project).

Next, define user relations within the project. Add a set of procedure methods that are identified by attributes.

CopyC#
[RelationProcedure(RelationProcedureType.Select, "Cartella.Classes.User")]
        public bool GetContacts(string galleryID, IFieldCollection[] targets)
        {
        }

        [RelationProcedure(RelationProcedureType.Insert, "Cartella.Classes.User")]
        public bool AddContact(IField ownerIDField, List<IField> targetUniqueIDFields)
        {
        }

        [RelationProcedure(RelationProcedureType.Remove, "Cartella.Classes.User")]
        public bool RemoveContacts(IField ownerIDField, List<IField> targetUniqueIDFields)
        {
        }

The attribute RelationProcedure marks the type of procedure and type of target object for the relation, for each relation method.

Important

Note: These methods are not part of any interface, and are indexed by their attributes. It is important that the attributes are specified correctly.

The database placeholder names for stored procedures must be implemented and the procedures added to the database later.

CopyC#
[RelationProcedure(RelationProcedureType.Select, "Cartella.Classes.User")]
        public bool GetContacts(string projectID, out IFieldCollection[] targets)
        {
            return base.selectRelations<SqlParameter>("sp_GetProjectContacts",
                "@projectID", projectID, out targets);
        }

        [RelationProcedure(RelationProcedureType.Insert, "Cartella.Classes.User")]
        public bool AddContact(IField ownerIDField, List<IField> targetUniqueIDFields)
        {
            return base.insertRelations<SqlParameter>(ownerIDField,
                targetUniqueIDFields, "@projectID", "@contactID", "sp_AddProjectContact");
        }

        [RelationProcedure(RelationProcedureType.Remove, "Cartella.Classes.User")]
        public bool RemoveContacts(IField ownerIDField, List<IField> targetUniqueIDFields)
        {
            return base.removeRelations<SqlParameter>(ownerIDField, targetUniqueIDFields,
                "@projectID", "@contactID", "sp_RemoveProjectContact");
        }