using System.Collections.Generic; using ShareeBike.Model.Connector.Filter; namespace ShareeBike.Model.User.Account { public static class AccountExtensions { /// Gets information whether user is logged in or not from account object. /// Object to get information from. /// True if user is logged in, false if not. public static bool GetIsLoggedIn(this IAccount account) { return !string.IsNullOrEmpty(account.Mail) && !string.IsNullOrEmpty(account.SessionCookie); } /// /// Filters bike groups depending on whether user has access to all groups of bikes. /// Some user may be "ShareeBike"- user only, some "Citybike" and some may be "ShareeBike" and "Citybike" users. /// /// Account to filter with. /// Groups to filter. /// Filtered bike groups. public static IEnumerable DoFilter( this IAccount account, IEnumerable 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. } } }