public async Task <ActionResult> SupervisorsList(SupervisorsPageViewModel vm)
        {
            if (string.IsNullOrEmpty(vm.SelectedMerchant))
            {
                return(this.JsonFailResult(Phrases.FieldShouldNotBeEmpty, "#selectedMerchant"));
            }

            var staffs = await _payInvoiceClient.GetEmployeesAsync(vm.SelectedMerchant);

            var filteredstaffs = new List <SupervisorViewModel>();

            foreach (var staff in staffs)
            {
                MerchantsSupervisorMembershipResponse supervisor =
                    await _payInternalClient.GetSupervisorMembershipWithMerchantsAsync(staff.Id);

                if (supervisor != null)
                {
                    var item = new SupervisorViewModel()
                    {
                        Id                   = staff.Id,
                        Email                = staff.Email,
                        FirstName            = staff.FirstName,
                        LastName             = staff.LastName,
                        SupervisingMerchants = supervisor.Merchants.ToList()
                    };
                    filteredstaffs.Add(item);
                }
            }
            var viewModel = new SupervisorsListViewModel
            {
                Employees        = filteredstaffs,
                SelectedMerchant = vm.SelectedMerchant
            };

            return(View(viewModel));
        }
        public async Task <InvoiceSource> GetSupervisingAsync(
            string merchantId,
            string employeeId,
            IReadOnlyList <InvoiceStatus> status,
            Period period,
            string searchValue,
            string sortField,
            bool sortAscending,
            int skip,
            int take)
        {
            MerchantsSupervisorMembershipResponse membership =
                await _payInternalClient.GetSupervisorMembershipWithMerchantsAsync(employeeId);

            var invoiceslist = new List <InvoiceModel>();

            if (membership?.Merchants.Any() ?? false)
            {
                foreach (var merchant in membership.Merchants)
                {
                    var invoices = await _payInvoiceClient.GetMerchantInvoicesAsync(merchant);

                    invoiceslist.AddRange(invoices);
                }
            }

            IReadOnlyList <Invoice> result =
                await FilterAsync(invoiceslist, period, searchValue, sortField, sortAscending);

            var source = new InvoiceSource
            {
                Total                = result.Count,
                CountPerStatus       = new Dictionary <InvoiceStatus, int>(),
                Balance              = 0,
                MainStatistic        = new Dictionary <InvoiceStatus, double>(),
                SummaryStatistic     = Enumerable.Empty <SummaryStatisticModel>(),
                Rates                = new Dictionary <string, double>(),
                HasErrorsInStatistic = false
            };

            if (status.Count > 0)
            {
                source.Items = result
                               .Where(o => status.Contains(o.Status))
                               .Skip(skip)
                               .Take(take)
                               .ToList();
            }
            else
            {
                source.Items = result
                               .Skip(skip)
                               .Take(take)
                               .ToList();
            }

            foreach (InvoiceStatus value in Enum.GetValues(typeof(InvoiceStatus)))
            {
                source.CountPerStatus[value] = result.Count(o => o.Status == value);
            }

            return(source);
        }