Created
May 20, 2013 14:55
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <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