public OperationResult <Delivery[]> GetDeliveries(long clientId) { return(InvokeOperations.InvokeOperation(() => { Logger.Trace("Get deliveries. clientId = {0}", clientId); var deliveries = signalServiceRepository.GetDeliveries(clientId); var accountInfos = accService.GetAccountsInfo(deliveries.Select(x => (long)x.Provider.id).ToArray()); if (!accountInfos.IsSuccess) { throw new OperationException(accountInfos.Error, accountInfos.Code); } var deliveriesResults = new List <Delivery>(); foreach (var accountInfo in accountInfos.Result) { var provider = deliveries.FirstOrDefault(x => x.Provider.id == accountInfo.AccountId); if (provider == null) { throw new Exception("Provider not found!"); } var deliveryResult = new Delivery { Login = accountInfo.Login, Avatar = accountInfo.Avatar, AccountId = accountInfo.AccountId, AccountType = accountInfo.AccountType, Balance = (decimal)accountInfo.Balance, Commission = provider.Provider.commission ?? 0.0m, Nickname = provider.Provider.nickname, WorkingDays = 0, Procent = 100 + (((decimal)accountInfo.Balance / 100) * (decimal)(accountInfo.Equity - accountInfo.Balance)), Equity = (decimal)accountInfo.Equity, Profit = (decimal)(accountInfo.Equity - accountInfo.Balance), Currency = accountInfo.Currency, Leverage = accountInfo.Leverage, IsVisible = provider.Provider.isvisible, RatingValue = provider.Provider.rating_value, RatingCount = provider.Provider.rating_count, SubscribersCount = deliveries. Where(x => x.Provider.id == provider.Provider.id && x.Subscription != null). Select(x => x.Subscription).Count(), Subscribers = new List <AccountConnection>(deliveries. Where(x => x.Provider.id == provider.Provider.id && x.Subscription != null).Select(x => new AccountConnection { AccountId = x.Subscriber.id, Avatar = x.Subscriber.avatar })) }; deliveriesResults.Add(deliveryResult); } return deliveriesResults.ToArray(); })); }