public IActionResult Post([FromBody] DataSourceManifest value) { if (ModelState.IsValid == false) { return(BadRequest(ModelState)); } try { if (value.DataSourceDefinition != null) { var dsdId = value.DataSourceDefinition.DataSourceDefinitionId; var dsd = _dbContext.DataSourceDefinitions.Find(dsdId); value.DataSourceDefinition = dsd; } _dbContext.DataSourceManifests.Add(value); _dbContext.SaveChanges(); return(Created("registry-repo/DataSourceManifest", _dbContext.Entry(value).GetDatabaseValues())); } catch (Exception e) { _logger.LogError(e.StackTrace); return(BadRequest()); } }
public IActionResult Put(Guid id, [FromBody] DataSourceManifest value) { if (ModelState.IsValid == false) { return(BadRequest(ModelState)); } try { var originalDataSourceManifest = (DataSourceManifest)_dbContext.DataSourceManifests .Include(dsm => dsm.DataSourceDefinition) .ThenInclude(dsd => dsd.DataTopic) .Include(dsm => dsm.DataSourceDefinition) .ThenInclude(dsd => dsd.DataInterfaceSpecification) .Include(dsm => dsm.DataSourceDefinitionParameters) .ThenInclude(p => p.Parameters) .FirstOrDefault(o => o.DataSourceManifestId == id); //remove all child elements //_dbContext.Remove(originalDataSourceManifest.DataSourceDefinitionParameters); //_dbContext.Remove(originalDataSourceManifest.DataSourceDefinition); originalDataSourceManifest.DataSourceDefinitionParameters.Parameters = value.DataSourceDefinitionParameters.Parameters; //find if the DataSourceDefinition has changed var dsdorig = _dbContext.DataSourceDefinitions.Find(value.DataSourceManifestId); if (dsdorig != null) { _dbContext.Remove(originalDataSourceManifest.DataSourceDefinition); originalDataSourceManifest.DataSourceDefinition = dsdorig; } //originalDataSourceManifest.DataSourceDefinition = value.DataSourceDefinition; _dbContext.Entry(originalDataSourceManifest).CurrentValues.SetValues(value); _dbContext.SaveChanges(); return(Ok(_dbContext.Entry(originalDataSourceManifest).GetDatabaseValues())); } catch (Exception ex) { _logger.LogError(ex.StackTrace); return(BadRequest()); } }
public IActionResult Put(Guid id, [FromBody] DataChannelDescriptor value) { if (ModelState.IsValid == false) { return(BadRequest(ModelState)); } try { var originalDataChannelDescriptor = (DataChannelDescriptor)_dbContext.DataChannelDescriptors .Include(dcd => dcd.DataSourceManifest.DataSourceManifestId) .Include(dcd => dcd.DataConsumerManifest.DataConsumerManifestId) .FirstOrDefault(o => o.DataChannelDescriptorId == id); DataSourceManifest dataSourceManifest = (from dsm in _dbContext.DataSourceManifests where dsm.DataSourceManifestId == value.DataSourceManifest.DataSourceManifestId select dsm).FirstOrDefault(); DataConsumerManifest dataConsumerManifest = (from dcm in _dbContext.DataConsumerManifests where dcm.DataConsumerManifestId == value.DataConsumerManifest.DataConsumerManifestId select dcm).SingleOrDefault(); if (dataSourceManifest != null) { originalDataChannelDescriptor.DataSourceManifest = dataSourceManifest; } if (dataConsumerManifest != null) { originalDataChannelDescriptor.DataConsumerManifest = dataConsumerManifest; } _dbContext.Entry(originalDataChannelDescriptor).CurrentValues.SetValues(value); _dbContext.SaveChanges(); return(Ok(_dbContext.Entry(originalDataChannelDescriptor).GetDatabaseValues())); } catch (Exception ex) { _logger.LogError(ex.StackTrace); return(BadRequest()); } }