public async Task <IActionResult> SaveAsync([FromBody] SaveSonarrSettingsModel model) { var tvShowsSettings = new TvShowsSettings { Client = DownloadClient.Sonarr, Command = model.Command.Trim(), Restrictions = model.Restrictions }; var sonarrSetting = new SonarrSettingsModel { Hostname = model.Hostname.Trim(), Port = model.Port, ApiKey = model.ApiKey.Trim(), BaseUrl = model.BaseUrl.Trim(), TvPath = model.TvPath, TvProfile = model.TvProfile, TvTags = model.TvTags ?? Array.Empty <int>(), TvLanguage = model.TvLanguage, TvUseSeasonFolders = model.TvUseSeasonFolders, AnimePath = model.AnimePath, AnimeProfile = model.AnimeProfile, AnimeTags = model.AnimeTags ?? Array.Empty <int>(), AnimeLanguage = model.AnimeLanguage, AnimeUseSeasonFolders = model.AnimeUseSeasonFolders, SearchNewRequests = model.SearchNewRequests, MonitorNewRequests = model.MonitorNewRequests, UseSSL = model.UseSSL, Version = model.Version }; DownloadClientsSettingsRepository.SetSonarr(tvShowsSettings, sonarrSetting); return(Ok(new { ok = true })); }
public async Task <IActionResult> SaveAsync([FromBody] SaveSonarrSettingsModel model) { var tvShowsSettings = new TvShowsSettings { Client = DownloadClient.Sonarr, Restrictions = model.Restrictions }; if (!model.Categories.Any()) { return(BadRequest($"At least one category is required.")); } if (model.Categories.Any(x => string.IsNullOrWhiteSpace(x.Name))) { return(BadRequest($"A category name is required.")); } foreach (var category in model.Categories) { category.Name = category.Name.Trim(); category.Tags = category.Tags; } if (new HashSet <string>(model.Categories.Select(x => x.Name.ToLower())).Count != model.Categories.Length) { return(BadRequest($"All categories must have different names.")); } if (new HashSet <int>(model.Categories.Select(x => x.Id)).Count != model.Categories.Length) { return(BadRequest($"All categories must have different ids.")); } if (model.Categories.Any(x => !Regex.IsMatch(x.Name, @"^[\w-]{1,32}$"))) { return(BadRequest($"Invalid categorie names, make sure they only contain alphanumeric characters, dashes and underscores. (No spaces, etc)")); } var sonarrSetting = new SonarrSettingsModel { Hostname = model.Hostname.Trim(), Port = model.Port, ApiKey = model.ApiKey.Trim(), BaseUrl = model.BaseUrl.Trim(), Categories = model.Categories, SearchNewRequests = model.SearchNewRequests, MonitorNewRequests = model.MonitorNewRequests, UseSSL = model.UseSSL, Version = model.Version }; DownloadClientsSettingsRepository.SetSonarr(tvShowsSettings, sonarrSetting); return(Ok(new { ok = true })); }