sharee.bike-App/TINKLib/Model/User/Account/AccountExtensions.cs

35 lines
1.4 KiB
C#
Raw Normal View History

2021-05-13 20:03:07 +02:00
using System.Collections.Generic;
using TINK.Model.Connector.Filter;
namespace TINK.Model.User.Account
{
public static class AccountExtensions
{
/// <summary> Gets information whether user is logged in or not from account object. </summary>
2021-11-08 23:11:56 +01:00
/// <param name="account">Object to get information from.</param>
2021-05-13 20:03:07 +02:00
/// <returns>True if user is logged in, false if not.</returns>
2021-11-08 23:11:56 +01:00
public static bool GetIsLoggedIn(this IAccount account)
2021-05-13 20:03:07 +02:00
{
2021-11-08 23:11:56 +01:00
return !string.IsNullOrEmpty(account.Mail)
&& !string.IsNullOrEmpty(account.SessionCookie);
2021-05-13 20:03:07 +02:00
}
/// <summary>
/// Filters bike groups depending on whether user has access to all groups of bikes.
/// Some user may be "TINK"- user only, some "Konrad" and some may be "TINK" and "Konrad" users.
/// </summary>
/// <param name="account">Account to filter with.</param>
/// <param name="filter">Groups to filter.</param>
/// <returns>Filtered bike groups.</returns>
public static IEnumerable<string> DoFilter(
this IAccount account,
IEnumerable<string> filter)
{
return GetIsLoggedIn(account)
? GroupFilterFactory.Create(account.Group).DoFilter(filter) // Filter if user is logged in.
: new NullGroupFilter().DoFilter(filter); // Do not filter if no user is logged in.
}
}
}