Finished adding subscriptions for TV Shows

This commit is contained in:
Jamie Rees 2018-05-16 12:07:46 +01:00
parent 7a9fc1213f
commit 16952cb44c
11 changed files with 95 additions and 29 deletions

View file

@ -138,10 +138,10 @@ namespace Ombi.Core.Engine
{
allRequests = await MovieRepository.GetWithUser().Skip(position).Take(count).OrderByDescending(x => x.ReleaseDate).ToListAsync();
}
allRequests.ForEach(x =>
allRequests.ForEach(async x =>
{
x.PosterPath = PosterPathHelper.FixPosterPath(x.PosterPath);
CheckForSubscription(shouldHide, x);
await CheckForSubscription(shouldHide, x);
});
return allRequests;
}
@ -176,19 +176,27 @@ namespace Ombi.Core.Engine
allRequests = await MovieRepository.GetWithUser().ToListAsync();
}
allRequests.ForEach(x =>
allRequests.ForEach(async x =>
{
x.PosterPath = PosterPathHelper.FixPosterPath(x.PosterPath);
CheckForSubscription(shouldHide, x);
await CheckForSubscription(shouldHide, x);
});
return allRequests;
}
private void CheckForSubscription(HideResult shouldHide, MovieRequests x)
private async Task CheckForSubscription(HideResult shouldHide, MovieRequests x)
{
var sub = _subscriptionRepository.GetAll().FirstOrDefaultAsync(s =>
s.UserId == shouldHide.UserId && s.RequestId == x.Id && s.RequestType == RequestType.Movie);
x.Subscribed = sub != null;
if (shouldHide.UserId == x.RequestedUserId)
{
x.ShowSubscribe = false;
}
else
{
x.ShowSubscribe = true;
var sub = await _subscriptionRepository.GetAll().FirstOrDefaultAsync(s =>
s.UserId == shouldHide.UserId && s.RequestId == x.Id && s.RequestType == RequestType.Movie);
x.Subscribed = sub != null;
}
}
/// <summary>
@ -209,10 +217,10 @@ namespace Ombi.Core.Engine
allRequests = await MovieRepository.GetWithUser().ToListAsync();
}
var results = allRequests.Where(x => x.Title.Contains(search, CompareOptions.IgnoreCase)).ToList();
results.ForEach(x =>
results.ForEach(async x =>
{
x.PosterPath = PosterPathHelper.FixPosterPath(x.PosterPath);
CheckForSubscription(shouldHide, x);
await CheckForSubscription(shouldHide, x);
});
return results;
}