Skip to content

Instantly share code, notes, and snippets.

@oexenhave
Created May 20, 2013 14:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oexenhave/5612745 to your computer and use it in GitHub Desktop.
Save oexenhave/5612745 to your computer and use it in GitHub Desktop.
Controller method for getting tasks from the TimeLog Project API and returning it as JSON
/// <summary>
/// Gets a list of tasks allocated to the currently authenticated user
/// </summary>
/// <returns>A JsonResult with tasks</returns>
public ActionResult Get()
{
// Prepare the envelope with a faulty state
JsonEnvelope<IEnumerable<Task>> result = new JsonEnvelope<IEnumerable<Task>> { Success = false, Data = new List<Task>(), Message = "No tasks" };
// Query the TimeLog Project web service for tasks allocated to the employee
var tasksResponse = SessionHelper.Instance.ProjectManagementClient.GetTasksAllocatedToEmployee(SessionHelper.Instance.Initials, SessionHelper.Instance.ProjectManagementToken);
// Check if the state is correct
if (tasksResponse.ResponseState == TimelogProjectManagement.ExecutionStatus.Success)
{
// Recreate the result including the task data
result = new JsonEnvelope<IEnumerable<Task>>
{
Success = true,
Data = tasksResponse.Return.Select(t => new Task
{
Id = t.ID,
Name = t.FullName,
ProjectId = t.Details.ProjectHeader.ID,
ProjectName = t.Details.ProjectHeader.Name
}),
Message = string.Empty
};
}
// Return the data as JSON
return new JsonResult { Data = result, JsonRequestBehavior = JsonRequestBehavior.AllowGet };
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment