This commit is contained in:
Jamie.Rees 2017-06-19 15:03:39 +01:00
parent d73899fc53
commit 974cb1ebb3
22 changed files with 289 additions and 131 deletions

View 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();
}
}
}