コード例 #1
0
        public IActionResult Post([FromBody] DataChannelDescriptor value)
        {
            if (ModelState.IsValid == false)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                //find manifests
                var dsd = _dbContext.DataSourceManifests.Find(value.DataSourceManifest.DataSourceManifestId);
                var dcd = _dbContext.DataConsumerManifests.Find(value.DataConsumerManifest.DataConsumerManifestId);

                if (dsd != null && dcd != null)
                {
                    value.DataConsumerManifest = dcd;
                    value.DataSourceManifest   = dsd;

                    _dbContext.DataChannelDescriptors.Add(value);
                    _dbContext.SaveChanges();
                    return(Created("registry-repo/DataConsumerManifest", _dbContext.Entry(value).GetDatabaseValues()));
                }
                else
                {
                    return(BadRequest("The Manifests do not exist in the registry"));
                }
            }
            catch (Exception e)
            {
                _logger.LogError(e.StackTrace);
                return(BadRequest());
            }
        }
コード例 #2
0
        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());
            }
        }