public async Task <IActionResult> Post([FromBody] ScheduleViewModel request) { if (request == null) { ModelState.AddModelError("Save", "No data passed"); return(BadRequest(ModelState)); } //Validate the cron expression if (!string.IsNullOrWhiteSpace(request.CRONExpression)) { try { CronExpression expression = CronExpression.Parse(request.CRONExpression, CronFormat.Standard); } catch (Exception ex) { ModelState.AddModelError("Save", string.Concat("Invalid cron expression, ", ex.Message)); return(BadRequest(ModelState)); } } Guid entityId = Guid.NewGuid(); try { Schedule requestObj = new Schedule(); requestObj.Id = entityId; requestObj.Name = request.Name; requestObj.AgentId = request.AgentId; requestObj.CRONExpression = request.CRONExpression; requestObj.LastExecution = request.LastExecution; requestObj.NextExecution = request.NextExecution; requestObj.IsDisabled = request.IsDisabled; requestObj.ProjectId = request.ProjectId; requestObj.StartingType = request.StartingType; requestObj.Status = request.Status; requestObj.ExpiryDate = request.ExpiryDate; requestObj.StartDate = request.StartDate; requestObj.ProcessId = request.ProcessId; var response = await base.PostEntity(requestObj); try { recurringJobManager.RemoveIfExists(requestObj.Id?.ToString()); if (request.IsDisabled == false && !request.StartingType.ToLower().Equals("manual")) { var jsonScheduleObj = JsonSerializer.Serialize <Schedule>(requestObj); backgroundJobClient.Schedule(() => hubManager.StartNewRecurringJob(jsonScheduleObj), new DateTimeOffset(requestObj.StartDate.Value)); } } catch (Exception ex) { } return(response); } catch (Exception ex) { return(ex.GetActionResult()); } }