Add logic for movie request count

pull/2467/head
Kenton Royal 6 years ago
parent 6ebe2deb52
commit 0e46e66a6d

@ -487,12 +487,35 @@ namespace Ombi.Core.Engine
public async Task<RequestQuotaCountModel> GetRemainingRequests()
{
OmbiUser user = await GetUser();
int limit = user.MovieRequestLimit ?? 0;
if (limit <= 0)
{
return new RequestQuotaCountModel()
{
HasLimit = false,
Limit = 0,
Remaining = 0,
NextRequest = DateTime.Now,
};
}
IQueryable<RequestLog> log = _requestLog.GetAll().Where(x => x.UserId == user.Id && x.RequestType == RequestType.Movie);
int count = limit - await log.CountAsync(x => x.RequestDate >= DateTime.UtcNow.AddDays(-7));
DateTime oldestRequestedAt = await log.Where(x => x.RequestDate >= DateTime.UtcNow.AddDays(-7))
.OrderBy(x => x.RequestDate)
.Select(x => x.RequestDate)
.FirstOrDefaultAsync();
return new RequestQuotaCountModel()
{
HasLimit = false,
Limit = 5,
Remaining = 4,
NextRequest = DateTime.Parse("2018-08-27T00:00:00+01"),
HasLimit = true,
Limit = limit,
Remaining = count,
NextRequest = oldestRequestedAt.AddDays(7),
};
}
}

Loading…
Cancel
Save