public OperationResult <Subscription[]> GetSubscriptions(long clientId) { return(InvokeOperations.InvokeOperation(() => { Logger.Trace("Get subscriptions, client id - {0}", clientId); var subscriptions = signalServiceRepository.GetSubscriptions(clientId); var subscriptionsResult = new List <Subscription>(); var accountIds = subscriptions.Select(x => x.Subscriber.id).Distinct(); foreach (var accountId in accountIds) { var subscriptionResult = new Subscription { AccountId = accountId, Profit = 0.0m, SubscribersCount = 0, Providers = new List <AccountConnection>() }; subscriptionsResult.Add(subscriptionResult); foreach (var subscription in subscriptions.Where(x => x.Subscriber.id == accountId)) { subscriptionResult.Profit += subscription.Subscription.slave_profit; subscriptionResult.SubscribersCount++; subscriptionResult.Providers.Add(new AccountConnection { AccountId = subscription.Provider.id, Avatar = subscription.Provider.avatar, Nickname = subscription.Provider.nickname }); } } return subscriptionsResult.ToArray(); })); }