Kentico CMS 6.0 Developer's Guide

Managing tasks

Managing tasks

Previous topic Next topic Mail us feedback on this topic!  

Managing tasks

Previous topic Next topic JavaScript is required for the print function Mail us feedback on this topic!  

Arrow


API examples for newer versions


Please visit the latest API Examples documentation to view API examples for newer versions of Kentico.



The following example creates a project management task.

 

private bool CreateProjectTask()
{

  ProjectInfo project = ProjectInfoProvider.GetProjectInfo("MyNewProject", CMSContext.CurrentSiteID, 0);
  ProjectTaskStatusInfo status = ProjectTaskStatusInfoProvider.GetProjectTaskStatusInfo("NotStarted");
  ProjectTaskPriorityInfo priority = ProjectTaskPriorityInfoProvider.GetProjectTaskPriorityInfo("Normal");

 

    if ((project != null) && (status != null) && (priority != null))
    {
        // Create new project task object
        ProjectTaskInfo newTask = new ProjectTaskInfo();
 
        int currentUserID = CMSContext.CurrentUser.UserID;
 
        // Set the properties
        newTask.ProjectTaskDisplayName = "My new task";
        newTask.ProjectTaskCreatedByID = currentUserID;
        newTask.ProjectTaskOwnerID = currentUserID;
        newTask.ProjectTaskAssignedToUserID = currentUserID;
        newTask.ProjectTaskStatusID = status.TaskStatusID;
        newTask.ProjectTaskPriorityID = priority.TaskPriorityID;
        newTask.ProjectTaskProjectID = project.ProjectID;
 
        // Save the project task
        ProjectTaskInfoProvider.SetProjectTaskInfo(newTask);
 
        return true;
    }
 
    return false;
}

 

The following example gets and updates a task.

 

private bool GetAndUpdateProjectTask()
{
    // Prepare the parameters
    string where = "ProjectTaskDisplayName LIKE N'My new task%'";
    string orderBy = "";
    int topN = 0;
    string columns = "";
 

  // Get the data
  DataSet tasks = ProjectTaskInfoProvider.GetProjectTasks(where, orderBy, topN, columns);

    if (!DataHelper.DataSourceIsEmpty(tasks))
    {
        // Get the project task
        ProjectTaskInfo updateTask = new ProjectTaskInfo(tasks.Tables[0].Rows[0]);
        if (updateTask != null)
        {

          // Update the properties
           updateTask.ProjectTaskDisplayName = updateTask.ProjectTaskDisplayName.ToLower();

 
            // Save the changes
            ProjectTaskInfoProvider.SetProjectTaskInfo(updateTask);
 
            return true;
        }
    }
 
    return false;
}

 

The following example gets and bulk updates tasks.

 

private bool GetAndBulkUpdateProjectTasks()
{
    // Prepare the parameters
    string where = "ProjectTaskDisplayName LIKE N'My new task%'";
    string orderBy = "";
    int topN = 0;
    string columns = "";

 

  // Get the data
  DataSet tasks = ProjectTaskInfoProvider.GetProjectTasks(where, orderBy, topN, columns);

    if (!DataHelper.DataSourceIsEmpty(tasks))
    {
        // Loop through the individual items
        foreach (DataRow taskDr in tasks.Tables[0].Rows)
        {
            // Create object from DataRow
            ProjectTaskInfo modifyTask = new ProjectTaskInfo(taskDr);

 
          // Update the properties
           modifyTask.ProjectTaskDisplayName = modifyTask.ProjectTaskDisplayName.ToUpper();

 

            // Save the changes
            ProjectTaskInfoProvider.SetProjectTaskInfo(modifyTask);
        }
 
        return true;
    }
 
    return false;
}

 

The following example deletes a task.

 

private bool DeleteProjectTask()
{
    // Prepare the parameters
    string where = "ProjectTaskDisplayName LIKE N'My new task%'";
    string orderBy = "";
    int topN = 0;
    string columns = "";
 

  // Get the data
  DataSet tasks = ProjectTaskInfoProvider.GetProjectTasks(where, orderBy, topN, columns);

    if (!DataHelper.DataSourceIsEmpty(tasks))
    {

      // Get the project task
      ProjectTaskInfo deleteTask = new ProjectTaskInfo(tasks.Tables[0].Rows[0]);

 
        // Delete the project task
        ProjectTaskInfoProvider.DeleteProjectTaskInfo(deleteTask);
 
        return (deleteTask != null);
    }
 
    return false;
}