From cfd0625df4998fdb497cd1ee83a2bac10a38ebb9 Mon Sep 17 00:00:00 2001 From: TidusJar Date: Fri, 28 Sep 2018 12:56:23 +0100 Subject: [PATCH] !wip --- src/Ombi.Core/Engine/VoteEngine.cs | 24 +++++++++++++++++++++--- src/Ombi.Core/Models/UI/VoteViewModel.cs | 16 ++++++++++++++++ 2 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 src/Ombi.Core/Models/UI/VoteViewModel.cs diff --git a/src/Ombi.Core/Engine/VoteEngine.cs b/src/Ombi.Core/Engine/VoteEngine.cs index 5bf8549e1..ecd22e848 100644 --- a/src/Ombi.Core/Engine/VoteEngine.cs +++ b/src/Ombi.Core/Engine/VoteEngine.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Linq; using System.Security.Principal; using System.Threading.Tasks; @@ -6,6 +7,7 @@ using Microsoft.EntityFrameworkCore; using Ombi.Core.Authentication; using Ombi.Core.Engine.Interfaces; using Ombi.Core.Models; +using Ombi.Core.Models.UI; using Ombi.Core.Rule.Interfaces; using Ombi.Core.Settings; using Ombi.Settings.Settings.Models; @@ -32,14 +34,30 @@ namespace Ombi.Core.Engine private readonly ITvRequestEngine _tvRequestEngine; private readonly IMovieRequestEngine _movieRequestEngine; - public async Task GetMovieViewModel() + public async Task> GetMovieViewModel() { - var requests = await _movieRequestEngine.GetRequests(); - foreach (var r in requests) + var vm = new List(); + var movieRequests = await _movieRequestEngine.GetRequests(); + foreach (var r in movieRequests) { // Make model var votes = GetVotes(r.Id, RequestType.Movie); + var upVotes = await votes.Where(x => x.VoteType == VoteType.Upvote).CountAsync(); + var downVotes = await votes.Where(x => x.VoteType == VoteType.Downvote).CountAsync(); + vm.Add(new VoteViewModel + { + Upvotes = upVotes, + Downvotes = downVotes, + RequestId = r.Id, + RequestType = RequestType.Movie, + Title = r.Title, + Image = r.PosterPath, + Background = r.Background, + Description = r.Overview + }); } + + return vm; } public IQueryable GetVotes(int requestId, RequestType requestType) diff --git a/src/Ombi.Core/Models/UI/VoteViewModel.cs b/src/Ombi.Core/Models/UI/VoteViewModel.cs new file mode 100644 index 000000000..71d6c95a9 --- /dev/null +++ b/src/Ombi.Core/Models/UI/VoteViewModel.cs @@ -0,0 +1,16 @@ +using Ombi.Store.Entities; + +namespace Ombi.Core.Models.UI +{ + public class VoteViewModel + { + public int RequestId { get; set; } + public RequestType RequestType { get; set; } + public string Image { get; set; } + public string Background { get; set; } + public int Upvotes { get; set; } + public int Downvotes { get; set; } + public string Title { get; set; } + public string Description { get; set; } + } +} \ No newline at end of file