public async Task <IActionResult> Post(ServiceTaskDto task) { if (task.TargetId == 0) { return(BadRequest(Json("Error: TargetId must be provided."))); } // If Criticality is provided it must be 1,2 or 3 if (task.Criticality < 0 || (int)task.Criticality > 3) { return(BadRequest(Json("Provided Criticality is invalid"))); } if (await _factoryDeviceService.Get(task.TargetId) == null) { return(NotFound(Json("Error: Target for task was not found."))); } ServiceTask newTask = new ServiceTask { Closed = task.Closed, Criticality = task.Criticality != 0 ? task.Criticality : TaskCriticality.Mild, // Default is Mild DateIssued = DateTime.Now, Description = task.Description ?? "No description provided.", TargetId = task.TargetId }; await _serviceTaskService.CreateAsync(newTask); return(Ok(Json("Service task created."))); }
public async Task <IActionResult> Put(ServiceTaskDto UpdateData, int id) { // If TargetId is provided it must be valid if (UpdateData.TargetId != 0) { FactoryDevice dev = await _factoryDeviceService.Get(UpdateData.TargetId); if (dev == null) { return(BadRequest(Json("Provided TargetId is invalid"))); } } // If Criticality is provided it must be 1,2 or 3 if (UpdateData.Criticality < 0 || (int)UpdateData.Criticality > 3) { return(BadRequest(Json("Provided Criticality is invalid"))); } ServiceTask updateData = new ServiceTask { Closed = UpdateData.Closed, Criticality = UpdateData.Criticality, Description = UpdateData.Description, TargetId = UpdateData.TargetId, TaskId = id }; await _serviceTaskService.UpdateAsync(updateData, id); return(Ok(Json("Edit successful."))); }