mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-30 19:40:05 -07:00
Fixed the issue where we did not check if they are already in sonarr when choosing certain options #1540
This commit is contained in:
parent
3e4f504165
commit
55c62772e4
3 changed files with 108 additions and 4 deletions
23
src/Ombi.Core/Rule/Rules/Request/SonarrCacheRequestRule.cs
Normal file
23
src/Ombi.Core/Rule/Rules/Request/SonarrCacheRequestRule.cs
Normal file
|
@ -0,0 +1,23 @@
|
|||
using System.Threading.Tasks;
|
||||
using Ombi.Core.Rule.Interfaces;
|
||||
using Ombi.Store.Context;
|
||||
using Ombi.Store.Entities.Requests;
|
||||
|
||||
namespace Ombi.Core.Rule.Rules.Request
|
||||
{
|
||||
public class SonarrCacheRequestRule : BaseRequestRule, IRules<BaseRequest>
|
||||
{
|
||||
public SonarrCacheRequestRule(IOmbiContext ctx)
|
||||
{
|
||||
_ctx = ctx;
|
||||
}
|
||||
|
||||
private readonly IOmbiContext _ctx;
|
||||
|
||||
public Task<RuleResult> Execute(BaseRequest obj)
|
||||
{
|
||||
var rule = new SonarrCacheRule(_ctx);
|
||||
return rule.Execute(obj);
|
||||
}
|
||||
}
|
||||
}
|
50
src/Ombi.Core/Rule/Rules/Search/SonarrCacheSearchRule.cs
Normal file
50
src/Ombi.Core/Rule/Rules/Search/SonarrCacheSearchRule.cs
Normal file
|
@ -0,0 +1,50 @@
|
|||
#region Copyright
|
||||
// /************************************************************************
|
||||
// Copyright (c) 2017 Jamie Rees
|
||||
// File: SonarrCacheSearchRule.cs
|
||||
// Created By: Jamie Rees
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
// ************************************************************************/
|
||||
#endregion
|
||||
|
||||
using System.Threading.Tasks;
|
||||
using Ombi.Core.Models.Search;
|
||||
using Ombi.Core.Rule.Interfaces;
|
||||
using Ombi.Store.Context;
|
||||
|
||||
namespace Ombi.Core.Rule.Rules.Search
|
||||
{
|
||||
public class SonarrCacheSearchRule : BaseSearchRule, IRules<SearchViewModel>
|
||||
{
|
||||
public SonarrCacheSearchRule(IOmbiContext ctx)
|
||||
{
|
||||
_ctx = ctx;
|
||||
}
|
||||
|
||||
private readonly IOmbiContext _ctx;
|
||||
|
||||
public Task<RuleResult> Execute(SearchViewModel obj)
|
||||
{
|
||||
var rule = new SonarrCacheRule(_ctx);
|
||||
return rule.Execute(obj);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -2,13 +2,13 @@
|
|||
using System.Threading.Tasks;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Ombi.Core.Models.Search;
|
||||
using Ombi.Core.Rule.Interfaces;
|
||||
using Ombi.Store.Context;
|
||||
using Ombi.Store.Entities;
|
||||
using Ombi.Store.Entities.Requests;
|
||||
|
||||
namespace Ombi.Core.Rule.Rules.Search
|
||||
namespace Ombi.Core.Rule.Rules
|
||||
{
|
||||
public class SonarrCacheRule : BaseSearchRule, IRules<SearchViewModel>
|
||||
public class SonarrCacheRule
|
||||
{
|
||||
public SonarrCacheRule(IOmbiContext ctx)
|
||||
{
|
||||
|
@ -17,6 +17,37 @@ namespace Ombi.Core.Rule.Rules.Search
|
|||
|
||||
private readonly IOmbiContext _ctx;
|
||||
|
||||
public async Task<RuleResult> Execute(BaseRequest obj)
|
||||
{
|
||||
if (obj.RequestType == RequestType.TvShow)
|
||||
{
|
||||
var vm = (ChildRequests) obj;
|
||||
var result = await _ctx.SonarrCache.FirstOrDefaultAsync(x => x.TvDbId == vm.Id);
|
||||
if (result != null)
|
||||
{
|
||||
if (vm.SeasonRequests.Any())
|
||||
{
|
||||
var sonarrEpisodes = _ctx.SonarrEpisodeCache;
|
||||
foreach (var season in vm.SeasonRequests)
|
||||
{
|
||||
foreach (var ep in season.Episodes)
|
||||
{
|
||||
// Check if we have it
|
||||
var monitoredInSonarr = sonarrEpisodes.Any(x =>
|
||||
x.EpisodeNumber == ep.EpisodeNumber && x.SeasonNumber == season.SeasonNumber
|
||||
&& x.TvDbId == vm.Id);
|
||||
if (monitoredInSonarr)
|
||||
{
|
||||
return new RuleResult{Message = "We already have this request, please choose the \"Select...\" option to refine your request"};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return new RuleResult { Success = true };
|
||||
}
|
||||
|
||||
public async Task<RuleResult> Execute(SearchViewModel obj)
|
||||
{
|
||||
if (obj.Type == RequestType.TvShow)
|
||||
|
@ -48,7 +79,7 @@ namespace Ombi.Core.Rule.Rules.Search
|
|||
}
|
||||
}
|
||||
}
|
||||
return Success();
|
||||
return new RuleResult { Success = true };
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue