mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-14 01:02:57 -07:00
Some rules #865
This commit is contained in:
parent
d73899fc53
commit
974cb1ebb3
22 changed files with 289 additions and 131 deletions
50
src/Ombi.Core/Rule/Rules/Search/ExistingRequestRule.cs
Normal file
50
src/Ombi.Core/Rule/Rules/Search/ExistingRequestRule.cs
Normal file
|
@ -0,0 +1,50 @@
|
|||
using System.Threading.Tasks;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Ombi.Core.Models.Requests;
|
||||
using Ombi.Core.Models.Requests.Movie;
|
||||
using Ombi.Core.Models.Search;
|
||||
using Ombi.Core.Requests.Models;
|
||||
using Ombi.Core.Rule.Interfaces;
|
||||
|
||||
namespace Ombi.Core.Rule.Rules.Search
|
||||
{
|
||||
public class ExistingRequestRule : BaseSearchRule, IRequestRules<SearchViewModel>
|
||||
{
|
||||
public ExistingRequestRule(IRequestService<MovieRequestModel> movie, IRequestService<TvRequestModel> tv)
|
||||
{
|
||||
Movie = movie;
|
||||
Tv = tv;
|
||||
}
|
||||
|
||||
private IRequestService<MovieRequestModel> Movie { get; }
|
||||
private IRequestService<TvRequestModel> Tv { get; }
|
||||
|
||||
public async Task<RuleResult> Execute(SearchViewModel obj)
|
||||
{
|
||||
var movieRequests = Movie.GetAllQueryable();
|
||||
var existing = await movieRequests.FirstOrDefaultAsync(x => x.ProviderId == obj.Id);
|
||||
if (existing != null) // Do we already have a request for this?
|
||||
{
|
||||
|
||||
obj.Requested = true;
|
||||
obj.Approved = existing.Approved;
|
||||
obj.Available = existing.Available;
|
||||
|
||||
return Success();
|
||||
}
|
||||
|
||||
var tvRequests = Tv.GetAllQueryable();
|
||||
var movieExisting = await tvRequests.FirstOrDefaultAsync(x => x.ProviderId == obj.Id);
|
||||
if (movieExisting != null) // Do we already have a request for this?
|
||||
{
|
||||
|
||||
obj.Requested = true;
|
||||
obj.Approved = movieExisting.Approved;
|
||||
obj.Available = movieExisting.Available;
|
||||
|
||||
return Success();
|
||||
}
|
||||
return Success();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue