public IHttpActionResult Update([FromUri] int id, [FromBody] PublisherUpdateModel game)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _publisherService = new PublisherServices();

            _publisherService.UpdatePublisher(id, game);

            return(Ok());
        }
        // Update Publisher
        public void UpdatePublisher(int id, PublisherUpdateModel publisherToUpdate)
        {
            using (var ctx = new ApplicationDbContext())
            {
                Publisher publisherWeWantToUpdate = ctx.Publisher.Find(publisherToUpdate.Name);

                if (publisherToUpdate != null)
                {
                    publisherWeWantToUpdate.Name = publisherToUpdate.Name;

                    ctx.SaveChanges();
                }
            }
        }
        public IHttpActionResult Put(Guid id, [FromBody] PublisherUpdateModel publisherModel)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest());
                }

                var updatedPublisher = Mapper.Map <Publisher>(publisherModel);
                updatedPublisher.Id = id;
                _publisherRepository.Update(updatedPublisher);
                return(Ok());
            }
            catch (InvalidOperationException)
            {
                return(NotFound());
            }
        }
        /// <inheritdoc/>
        public async Task UpdatePublisherAsync(string publisherId,
                                               PublisherUpdateModel request, CancellationToken ct)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }
            if (string.IsNullOrEmpty(publisherId))
            {
                throw new ArgumentException(nameof(publisherId));
            }

            // Get existing endpoint and compare to see if we need to patch.
            var deviceId = SupervisorModelEx.ParseDeviceId(publisherId, out var moduleId);

            while (true)
            {
                try {
                    var twin = await _iothub.GetAsync(deviceId, moduleId, ct);

                    if (twin.Id != deviceId && twin.ModuleId != moduleId)
                    {
                        throw new ArgumentException("Id must be same as twin to patch",
                                                    nameof(publisherId));
                    }

                    var registration = twin.ToEntityRegistration(true) as PublisherRegistration;
                    if (registration == null)
                    {
                        throw new ResourceNotFoundException(
                                  $"{publisherId} is not a publisher registration.");
                    }
                    // Update registration from update request
                    var patched = registration.ToServiceModel();
                    if (request.SiteId != null)
                    {
                        patched.SiteId = string.IsNullOrEmpty(request.SiteId) ?
                                         null : request.SiteId;
                    }

                    if (request.LogLevel != null)
                    {
                        patched.LogLevel = request.LogLevel == TraceLogLevel.Information ?
                                           null : request.LogLevel;
                    }

                    if (request.Configuration != null)
                    {
                        if (patched.Configuration == null)
                        {
                            patched.Configuration = new PublisherConfigModel();
                        }
                        if (request.Configuration.JobOrchestratorUrl != null)
                        {
                            patched.Configuration.JobOrchestratorUrl =
                                string.IsNullOrEmpty(
                                    request.Configuration.JobOrchestratorUrl.Trim()) ?
                                null : request.Configuration.JobOrchestratorUrl;
                        }
                        if (request.Configuration.HeartbeatInterval != null)
                        {
                            patched.Configuration.HeartbeatInterval =
                                request.Configuration.HeartbeatInterval.Value.Ticks == 0 ?
                                null : request.Configuration.HeartbeatInterval;
                        }
                        if (request.Configuration.JobCheckInterval != null)
                        {
                            patched.Configuration.JobCheckInterval =
                                request.Configuration.JobCheckInterval.Value.Ticks == 0 ?
                                null : request.Configuration.JobCheckInterval;
                        }
                        if (request.Configuration.MaxWorkers != null)
                        {
                            patched.Configuration.MaxWorkers =
                                request.Configuration.MaxWorkers <= 0 ?
                                null : request.Configuration.MaxWorkers;
                        }
                        if (request.Configuration.Capabilities != null)
                        {
                            patched.Configuration.Capabilities =
                                request.Configuration.Capabilities.Count == 0 ?
                                null : request.Configuration.Capabilities;
                        }
                    }
                    // Patch
                    twin = await _iothub.PatchAsync(registration.Patch(
                                                        patched.ToPublisherRegistration(), _serializer), false, ct);

                    // Send update to through broker
                    registration = twin.ToEntityRegistration(true) as PublisherRegistration;
                    await _broker.NotifyAllAsync(l => l.OnPublisherUpdatedAsync(null,
                                                                                registration.ToServiceModel()));

                    return;
                }
                catch (ResourceOutOfDateException ex) {
                    _logger.Debug(ex, "Retrying updating supervisor...");
                    continue;
                }
            }
        }
 /// <inheritdoc/>
 public async Task UpdatePublisherAsync(string id, PublisherUpdateModel request,
                                        CancellationToken ct)
 {
     await _client.UpdatePublisherAsync(id, request.ToApiModel(), ct);
 }