We will now create a Manager Class for our new Project class

The ProjectsManager class will handle selecting, creating, deleting, and purging of Project instances.

The manager classes are essential to the Cartella architecture. They control the instances and database manipulations.

Create an Interface

Define an IProjectsManager interface. This manager will provide the Select, Create, and Remove functions specific to the Project type. It will also provide a generic definition for IFolioItem managers. The members are aliases of IFolioItemManager members.

CopyC#
using System;
using Cartella.Interfaces;

namespace Cartella.Interfaces
{
    public interface IProjectsManager : IFolioItemManager
    {
        /// <summary>
        /// Select a single project by its ID
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        IProject SelectSingleProject(string id);

        /// <summary>
        /// Select projects associated with a given folio Module (instance of presentation module specific to a folio)
        /// </summary>
        /// <param name="folioModule"></param>
        /// <param name="recursive"></param>
        /// <returns></returns>
        IProject[] SelectProjects(IFolioModule folioModule, bool recursive);

        /// <summary>
        /// Create a new project with given parameters
        /// </summary>
        /// <param name="name"></param>
        /// <param name="description"></param>
        /// <param name="asset"></param>
        /// <param name="startDate"></param>
        /// <param name="projectedEndDate"></param>
        /// <param name="folioModule"></param>
        /// <returns></returns>
        IProject CreateProject(string name, string description, IAsset asset, DateTime startDate, DateTime projectedEndDate,
            IFolioModule folioModule);

        /// <summary>
        /// Mark a project as deleted
        /// </summary>
        /// <param name="project"></param>
        /// <returns></returns>
        bool RemoveProject(ref IProject project);
    }
}

Create the "ProjectManager" class

Create the ProjectsManager class and implement the FolioItemManager class and the new IProjectsManager interface. The base code should look like this:

CopyC#
using System;
using System.Linq;
using Cartella.Classes;
using Cartella.Interfaces;


namespace Cartella.Classes
{
    public class ProjectsManager : FolioItemManager, IProjectsManager
    {

        public ProjectsManager(ISiteManager siteMan)
            : base(siteMan)
     {
     }

        public override Type ObjectType
        {
            get { throw new NotImplementedException(); }
        }

        #region IProjectsManager Members

        public IProject SelectSingleProject(string id)
        {
            throw new NotImplementedException();
        }

        public IProject[] SelectProjects(IFolioModule folioModule, bool recursive)
        {
            throw new NotImplementedException();
        }

        public IProject CreateProject(string name, string description, IAsset asset, DateTime 
        startDate, DateTime projectedEndDate, IFolioModule folioModule)
        {
            throw new NotImplementedException();
        }

        public bool RemoveProject(ref IProject project)
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}

Filling Out our Manager Class

  1. You must have a constructor taking an ISiteManager as a parameter.

    CopyC#
    public ProjectsManager(ISiteManager siteMan)
                : base(siteMan)
                {
                }
  2. The ObjectType property allows the Site Manager to index this manager instance. It returns the type Project.

    CopyC#
    public override Type ObjectType
            {
                get
                {
                    return typeof(Project);
                }
            }
  3. Create your CRUD methods.

    • SelectSingleProject method: Alias for SelectSingleFolioItem method.

      CopyC#
      public IProject SelectSingleProject(string id)
              {
                  return base.SelectSingleFolioItem<Project>(id);
              }
    • SelectProjects method: an alias for the SelectMultipleFolioItems method.

      CopyC#
      public IProject[] SelectProjects(IFolioModule folioModule, bool recursive)
              {
                  return base.SelectMultipleEntities<Project>().Where(proj => proj.OwnerModule.ID == folioModule.ID).ToArray();
              }
    • CreateProject method: accepts a list of fields and passes them to CreateFolioItem method from base class.

      CopyC#
      public IProject CreateProject(string name, string description, IAsset asset, DateTime 
              startDate, DateTime projectedEndDate, IFolioModule folioModule)
              {
                  FieldCollection fields = new FieldCollection();
                  fields.Add(new Field(new FieldDefinition(
                      "Name"), name));
                  fields.Add(new Field(new FieldDefinition(
                      "Description"), description));
                  fields.Add(new Field(new FieldDefinition(
                      "EX_Asset"), asset.ID));
                  fields.Add(new Field(new FieldDefinition(
                      "EX_Z1StartDate"), startDate.ToShortDateString()));
                  fields.Add(new Field(new FieldDefinition(
                      "EX_Z2ProjectedEndDate"), projectedEndDate.ToShortDateString()));
      
                  Project proj = CreateFolioItem<Project>(fields, folioModule);
                  return proj;
              }
    • RemoveProject method: an alias for RemoveFolioItem method

      CopyC#
      public bool RemoveProject(ref IProject project)
              {
                  return base.RemoveFolioItem<IProject>(ref project);
              }

    The ProjectsManager class is now complete.