public async Task <IActionResult> Put(string id, [FromBody] CreateJobViewModel request) { try { Guid entityId = new Guid(id); var existingJob = repository.GetOne(entityId); if (existingJob == null) { return(NotFound("Unable to find a Job for the specified ID")); } Automation automation = automationRepo.GetOne(existingJob.AutomationId ?? Guid.Empty); if (automation == null) //no automation was found { ModelState.AddModelError("Save", "No automation was found for the specified automation ID"); return(NotFound(ModelState)); } AutomationVersion automationVersion = automationVersionRepo.Find(null, q => q.AutomationId == automation.Id).Items?.FirstOrDefault(); existingJob.AutomationVersion = automationVersion.VersionNumber; existingJob.AutomationVersionId = automationVersion.Id; existingJob.AgentId = request.AgentId; existingJob.StartTime = request.StartTime; existingJob.EndTime = request.EndTime; existingJob.ExecutionTimeInMinutes = (existingJob.EndTime.Value - existingJob.StartTime).Value.TotalMinutes; existingJob.DequeueTime = request.DequeueTime; existingJob.AutomationId = request.AutomationId; existingJob.JobStatus = request.JobStatus; existingJob.Message = request.Message; existingJob.IsSuccessful = request.IsSuccessful; var response = await base.PutEntity(id, existingJob); jobManager.DeleteExistingParameters(entityId); var set = new HashSet <string>(); foreach (var parameter in request.JobParameters ?? Enumerable.Empty <JobParameter>()) { if (!set.Add(parameter.Name)) { ModelState.AddModelError("JobParameter", "JobParameter Name Already Exists"); return(BadRequest(ModelState)); } parameter.JobId = entityId; parameter.CreatedBy = applicationUser?.UserName; parameter.CreatedOn = DateTime.UtcNow; parameter.Id = Guid.NewGuid(); jobParameterRepo.Add(parameter); } if (request.EndTime != null) { jobManager.UpdateAutomationAverages(existingJob.Id); } //send SignalR notification to all connected clients await webhookPublisher.PublishAsync("Jobs.JobUpdated", existingJob.Id.ToString()).ConfigureAwait(false); await _hub.Clients.All.SendAsync("sendjobnotification", string.Format("Job id {0} updated.", existingJob.Id)); return(response); } catch (Exception ex) { ModelState.AddModelError("Job", ex.Message); return(BadRequest(ModelState)); } }