public async Task <IActionResult> Update([FromBody] UpdateMaintenanceTaskDto maintenanceTask) { try { if (!ModelState.IsValid) { var errors = ModelState.Values.Select(inv => inv.Errors.Select(er => er.ErrorMessage)); return(BadRequest(new { errors })); } var task = await _service.Update(new MaintenanceTask { Id = (int)maintenanceTask.Id, FactoryDeviceId = maintenanceTask.FactoryDeviceId, Description = maintenanceTask.Description, Criticality = (Criticality)maintenanceTask.Criticality, Done = (bool)maintenanceTask.Done, }); if (task != null) { return(Ok(new MaintenanceTaskDto { Id = task.Id, FactoryDeviceId = task.FactoryDeviceId, Description = task.Description, Criticality = task.Criticality.ToString(), Done = task.Done, Time = task.Time })); } else { return(Conflict()); } } catch (DbUpdateException dbue) { ConsoleLogError("Update", dbue, "DbUpdateException"); return(Conflict()); } catch (Exception e) { ConsoleLogError("Update", e); return(StatusCode(500)); } }
private async Task <MaintenanceTask> UpdateMT( IMaintenanceTaskService service, MaintenanceTask task) { return(await service.Update(task)); }