-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIItemHelper.cs
More file actions
57 lines (50 loc) · 2.73 KB
/
IItemHelper.cs
File metadata and controls
57 lines (50 loc) · 2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
using Upsilon.Apps.Passkey.Interfaces.Models;
namespace Upsilon.Apps.Passkey.GUI.WPF.Helper
{
public static class IItemHelper
{
public static void Shake(this IUser user)
{
_ = user.ItemId;
}
public static bool MeetsFilterConditions(this IService service, string serviceFilter, string identifierFilter, string globalTextFilter, bool changedItemsOnly)
{
serviceFilter = serviceFilter.ToLower().Trim();
identifierFilter = identifierFilter.ToLower().Trim();
globalTextFilter = globalTextFilter.ToLower().Trim();
string serviceId = service.ItemId.Replace(service.User.ItemId, string.Empty).ToLower().Trim();
string serviceName = service.ServiceName.ToLower().Trim();
string url = service.Url.ToLower().Trim();
string notes = service.Notes.ToLower().Trim();
return (!string.IsNullOrWhiteSpace(globalTextFilter)
? serviceId == globalTextFilter
|| serviceName.Contains(globalTextFilter)
|| url.Contains(globalTextFilter)
|| notes.Contains(globalTextFilter)
|| service.Accounts.Any(x => x.MeetsFilterConditions(string.Empty, globalTextFilter, changedItemsOnly))
: (string.IsNullOrWhiteSpace(serviceFilter)
|| (!string.IsNullOrWhiteSpace(serviceFilter) && serviceName.Contains(serviceFilter)))
&& (string.IsNullOrWhiteSpace(identifierFilter)
|| service.Accounts.Any(x => x.MeetsFilterConditions(identifierFilter, globalTextFilter, changedItemsOnly))))
&& (!changedItemsOnly || service.HasChanged());
}
public static bool MeetsFilterConditions(this IAccount account, string identifierFilter, string globalTextFilter, bool changedItemsOnly)
{
identifierFilter = identifierFilter.ToLower().Trim();
globalTextFilter = globalTextFilter.ToLower().Trim();
string accountId = account.ItemId.Replace(account.Service.ItemId, string.Empty).ToLower().Trim();
string label = account.Label.ToLower().Trim();
string notes = account.Notes.ToLower().Trim();
string identifiers = string.Join("\n", account.Identifiers.Select(x => x.ToLower().Trim()));
return (!string.IsNullOrWhiteSpace(globalTextFilter)
? accountId == globalTextFilter
|| identifiers.Contains(globalTextFilter)
|| label.ToLower().Contains(globalTextFilter)
|| notes.ToLower().Contains(globalTextFilter)
: string.IsNullOrWhiteSpace(identifierFilter)
|| identifiers.Contains(identifierFilter)
|| label.Contains(identifierFilter))
&& (!changedItemsOnly || account.HasChanged());
}
}
}