public IHttpActionResult PostTaskAssignment(TaskAssignment taskAssignment)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            db.TaskAssignments.Add(taskAssignment);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (TaskAssignmentExists(taskAssignment.TaskId))
                {
                    return Conflict();
                }
                else
                {
                    throw;
                }
            }

            return CreatedAtRoute("DefaultApi", new { id = taskAssignment.TaskId }, taskAssignment);
        }
        //Made public while working on it
        public TaskAssignment getTaskAssignment(int GroupId, int TaskId)
        {
            //"Select A.TaskId, A.AccessType, A.GroupId
            //from TaskAssignment A
            //Join Task T
            //on T.TaskId = A.TaskId
            //and Status <> 'Closed'
            //where GroupId in (2) and TaskId = TaskId "
            //--1
            ApprovalProcessType TypeDefinition;
            BranchNode NodeDef;
            GroupRoleRelation GroupRels;
            TaskAssignment TA;
            TaskNode TN;
            ReviewTask reviewTask;

            TA = new TaskAssignment();
            db.Database.Log = s => System.Diagnostics.Debug.WriteLine(s);

            IEnumerable<TaskAssignment> TaskAssignments = db.TaskAssignments.Where(
                    r =>
                    r.Task.Status != "Closed" && r.GroupId == GroupId
                    && r.TaskId == TaskId);

            System.Diagnostics.Debug.WriteLine(TaskAssignments.ToString());
            //QUick for demo - no iteration or collection used
            TA = TaskAssignments.First();

            return TA;
        }
        public void InitialiseWorkflow()
        {
            //TODO: Error Checking

            int StartNodeId;
            int NodeId;
            int AccessType;
            int RelationType;
            int RelativeGroupId;                //This will need to be an array in later iterations, to allow for multiple branches
            String StartNodeText = "Start";

            ApprovalProcessType TypeDefinition;
            BranchNode NodeDef;
            GroupRoleRelation GroupRels;
            TaskAssignment TA;
            TaskNode TN;
            ReviewTask reviewTask;          //Can't be called Task as that causes interesting things to happen since .net defines a Task type already

            //Get Start Node for this Workflow Process Type
            TypeDefinition = db.ApprovalProcessTypes.FirstOrDefault(a => a.ApprovalProcessId.Equals(ApprovalProcessId));
            StartNodeId = (int)TypeDefinition.StartNodeId;
            //Get Relationship to use to send this Node off for approval
            NodeDef = db.BranchNodes.FirstOrDefault(a => a.NodeId.Equals(StartNodeId)  && a.Type.Equals(StartNodeText));
            //Note forcing one row returned from NodeDef
            NodeId = NodeDef.NodeId;
            AccessType = (int)NodeDef.AccessType;
            RelationType = NodeDef.RelationTypeId;
            //Just done one group for demonstration purposes
            //&& a.RelationTypeId.Equals(RelationType)
            //Has value
            GroupRels = db.GroupRoleRelations.FirstOrDefault(a => a.ApprovalProcessId ==ApprovalProcessId && a.MasterGroupId == MasterGroupId && a.RelationTypeId.Equals(RelationType));
            RelativeGroupId = (int)GroupRels.RelativeGroupId;

            reviewTask = new ReviewTask();
            TA = new TaskAssignment();
            TN = new TaskNode();

            reviewTask.ApprovalProcessType = ApprovalProcessId;
            reviewTask.RaiserUserId = RaiserUserId;
            reviewTask.Status = "I";
            reviewTask.DateUpdated = System.DateTime.Today;

            db.ReviewTasks.Add(reviewTask);
            db.SaveChanges();

            TA.AccessType = AccessType.ToString();
            TA.DateAssigned = System.DateTime.Today;
            TA.GroupId = RelativeGroupId;
            TA.TaskId = reviewTask.TaskId;
            TA.NodeId = NodeId;
            db.TaskAssignments.Add(TA);

            TN.NodeId = NodeId;
            TN.GroupId = RelativeGroupId;
            TN.TaskId = reviewTask.TaskId;
            TN.DateUpdated = System.DateTime.Today;
            db.TaskNodes.Add(TN);

            db.SaveChanges();

            //Should really return a success/fail indicator here
        }
        public IHttpActionResult PutTaskAssignment(int id, TaskAssignment taskAssignment)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != taskAssignment.TaskId)
            {
                return BadRequest();
            }

            db.Entry(taskAssignment).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TaskAssignmentExists(id))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return StatusCode(HttpStatusCode.NoContent);
        }