public AppIndexerMap Update(AppIndexerMap appIndexerMap)
 {
     return(_appIndexerMapRepository.Update(appIndexerMap));
 }
        private void SyncIndexers(List <IApplication> applications, List <IndexerDefinition> indexers, bool removeRemote = false)
        {
            foreach (var app in applications)
            {
                var indexerMappings = _appIndexerMapService.GetMappingsForApp(app.Definition.Id);

                //Get Dictionary of Remote Indexers point to Prowlarr and what they are mapped to
                var remoteMappings = ExecuteAction(a => a.GetIndexerMappings(), app);

                if (remoteMappings == null)
                {
                    continue;
                }

                //Add mappings if not already in db, these were setup manually in the app or orphaned by a table wipe
                foreach (var mapping in remoteMappings)
                {
                    if (!indexerMappings.Any(m => (m.RemoteIndexerId > 0 && m.RemoteIndexerId == mapping.RemoteIndexerId) || (m.RemoteIndexerName.IsNotNullOrWhiteSpace() && m.RemoteIndexerName == mapping.RemoteIndexerName)))
                    {
                        var addMapping = new AppIndexerMap
                        {
                            AppId             = app.Definition.Id,
                            RemoteIndexerId   = mapping.RemoteIndexerId,
                            RemoteIndexerName = mapping.RemoteIndexerName,
                            IndexerId         = mapping.IndexerId
                        };

                        _appIndexerMapService.Insert(addMapping);
                        indexerMappings.Add(addMapping);
                    }
                }

                foreach (var indexer in indexers)
                {
                    var definition = indexer;

                    if (indexerMappings.Any(x => x.IndexerId == definition.Id))
                    {
                        if (((ApplicationDefinition)app.Definition).SyncLevel == ApplicationSyncLevel.FullSync)
                        {
                            ExecuteAction(a => a.UpdateIndexer(definition), app);
                        }
                    }
                    else
                    {
                        if (indexer.Enable)
                        {
                            ExecuteAction(a => a.AddIndexer(definition), app);
                        }
                    }
                }

                if (removeRemote)
                {
                    var allIndexers = _indexerFactory.All();

                    foreach (var mapping in indexerMappings)
                    {
                        if (!allIndexers.Any(x => x.Id == mapping.IndexerId))
                        {
                            _logger.Info("Indexer with the ID {0} was found within {1} but is no longer defined within Prowlarr, this is being removed.", mapping.IndexerId, app.Name);
                            ExecuteAction(a => a.RemoveIndexer(mapping.IndexerId), app);
                        }
                    }
                }
            }
        }
 public AppIndexerMap Insert(AppIndexerMap appIndexerMap)
 {
     return(_appIndexerMapRepository.Insert(appIndexerMap));
 }