public async Task <IActionResult> ChangeStatus(string id, JobStatusType status, [BindRequired, FromQuery] string agentId, [FromBody] JobErrorViewModel jobErrors)
        {
            try
            {
                if (id == null)
                {
                    ModelState.AddModelError("ChangeStatus", "No Job ID was passed");
                    return(BadRequest(ModelState));
                }

                bool isValid = Guid.TryParse(id, out Guid agentGuid);
                if (!isValid)
                {
                    ModelState.AddModelError("ChangeStatus", "Job ID is not a valid GUID ");
                    return(BadRequest(ModelState));
                }
                if (status == null)
                {
                    ModelState.AddModelError("ChangeStatus", "No status was provided");
                    return(BadRequest(ModelState));
                }

                Guid entityId = new Guid(id);

                var existingJob = _repository.GetOne(entityId);
                if (existingJob == null)
                {
                    return(NotFound("Unable to find a Job for the specified ID"));
                }

                if (existingJob.AgentId.ToString() != agentId)
                {
                    return(UnprocessableEntity("The provided Agent ID does not match the Job's Agent ID"));
                }

                switch (status)
                {
                case JobStatusType.Completed:
                    existingJob.IsSuccessful = true;
                    break;

                case JobStatusType.Failed:
                    existingJob.IsSuccessful = false;
                    break;
                }

                existingJob.JobStatus             = status;
                existingJob.ErrorReason           = string.IsNullOrEmpty(jobErrors.ErrorReason) ? existingJob.ErrorReason : jobErrors.ErrorReason;
                existingJob.ErrorCode             = string.IsNullOrEmpty(jobErrors.ErrorCode) ? existingJob.ErrorCode : jobErrors.ErrorReason;
                existingJob.SerializedErrorString = string.IsNullOrEmpty(jobErrors.SerializedErrorString) ? existingJob.SerializedErrorString : jobErrors.ErrorReason;

                //update automation log and automation execution log counts for existing job
                if (status.Equals(JobStatusType.Completed) || status.Equals(JobStatusType.Failed))
                {
                    existingJob.AutomationLogCount          = _automationLogRepo.Find(null, q => q.JobId == existingJob.Id).Items.Count;
                    existingJob.AutomationExecutionLogCount = _automationExecutionLogRepo.Find(null, q => q.JobID == existingJob.Id).Items.Count;
                }

                var response = await base.PutEntity(id, existingJob);

                //send SignalR notification to all connected clients
                await _hub.Clients.All.SendAsync("sendjobnotification", string.Format("Job id {0} updated.", existingJob.Id));

                await _webhookPublisher.PublishAsync("Jobs.JobUpdated", existingJob.Id.ToString()).ConfigureAwait(false);

                return(response);
            }
            catch (Exception ex)
            {
                return(ex.GetActionResult());
            }
        }