mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-08-20 05:13:18 -07:00
add a better way to merge RequestedBy and RequestedUsers to avoid code duplication and simplify checks
This commit is contained in:
parent
a668ea04ec
commit
1ca3e0532b
2 changed files with 23 additions and 17 deletions
|
@ -4,6 +4,7 @@ using System.Security.Cryptography;
|
|||
using Dapper.Contrib.Extensions;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace PlexRequests.Store
|
||||
{
|
||||
|
@ -39,14 +40,28 @@ namespace PlexRequests.Store
|
|||
public string SeasonsRequested { get; set; }
|
||||
public List<string> RequestedUsers { get; set; }
|
||||
|
||||
[JsonIgnore]
|
||||
public List<string> AllUsers
|
||||
{
|
||||
get
|
||||
{
|
||||
var u = new List<string>();
|
||||
if (!string.IsNullOrEmpty(RequestedBy))
|
||||
{
|
||||
u.Add(RequestedBy);
|
||||
}
|
||||
|
||||
if (RequestedUsers.Any())
|
||||
{
|
||||
u.AddRange(RequestedUsers.Where(requestedUser => requestedUser != RequestedBy));
|
||||
}
|
||||
return u;
|
||||
}
|
||||
}
|
||||
|
||||
public bool UserHasRequested(string username)
|
||||
{
|
||||
bool alreadyRequested = !string.IsNullOrEmpty(RequestedBy) && RequestedBy.Equals(username, StringComparison.OrdinalIgnoreCase);
|
||||
if (!alreadyRequested && RequestedUsers != null && RequestedUsers.Count > 0)
|
||||
{
|
||||
alreadyRequested = RequestedUsers.Any(x => x.Equals(username, StringComparison.OrdinalIgnoreCase));
|
||||
}
|
||||
return alreadyRequested;
|
||||
return AllUsers.Any(x => x.Equals(username, StringComparison.OrdinalIgnoreCase));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue