public RevenueSummaryViewModel GetSummaryData(ClientAuthenticationViewModel credentials, DateTime fromDate, DateTime toDate)
        {
            var result = new RevenueSummaryViewModel
            {
                Details = new List<RevenueSummaryDetailViewModel>()
            };

            using (var client = new WDServiceProxy.WhiteDeliveryServiceClient())
            {
                try
                {
                    var items = client.GetListManagementReportSummaryData(GetDefaultFilters(credentials.MonetizeId, fromDate, toDate));

                    items.ToList().ForEach(x =>
                    {
                        var summaryRow = new RevenueSummaryDetailViewModel
                        {
                            AffiliateRevenue = x.AffiliateRevenue,
                            GrossRevenue = x.GrossRevenue,
                            Month = x.Month,
                            MonthName = x.MonthName,
                            Year = x.Year
                        };

                        result.Details.Add(summaryRow);
                    });
                }
                catch (Exception e)
                {
                    _logger.ErrorException("GetSummaryData", e);
                }
            }

            return result;
        }
        public RevenueSummaryViewModel GetSummaryData(ClientAuthenticationViewModel credentials, DateTime fromDate, DateTime toDate)
        {
            var consolidated = default(RevenueSummaryViewModel);

            try
            {
                var fromMonetizeIt = _monetizeItService.GetSummaryData(credentials, fromDate, toDate);
                
                consolidated = new RevenueSummaryViewModel
                {
                    AffiliateAccountName = DataHelper.GetClientName(credentials.MarketAffiliateId),
                    Details = _marketService.GetSummaryData(credentials, fromDate, toDate).Details.OrderByDescending(x => x.Year).ThenByDescending(x => x.Month).ToList()
                };

                fromMonetizeIt.Details.ForEach(x =>
                {
                    var existingRow = consolidated.Details.FirstOrDefault(r => (r.Month == x.Month) && (r.Year == x.Year));

                    if (existingRow != null)
                    {
                        existingRow.AffiliateRevenue += x.AffiliateRevenue;
                        existingRow.GrossRevenue += x.GrossRevenue;
                    }
                    else
                    {
                        consolidated.Details.Add(x);
                    }
                });
            }
            catch (Exception e)
            {
                _logger.ErrorException("GetSummaryData", e);
            }

            return consolidated;
        }
        public RevenueSummaryViewModel GetSummaryData(ClientAuthenticationViewModel credentials, DateTime fromDate, DateTime toDate)
        {
            var result = new RevenueSummaryViewModel
            {
                Details = new List<RevenueSummaryDetailViewModel>()
            };

            fromDate = new DateTime(fromDate.Year,fromDate.Month,1);
            toDate = new DateTime(toDate.Year, toDate.Month, 1).AddMonths(1).AddDays(-1);

            for (var date = fromDate; date <= toDate; date = date.AddMonths(1))
            {
                result.Details.Add(new RevenueSummaryDetailViewModel
                {
                    AffiliateRevenue = 0,
                    GrossRevenue = 0,
                    Month = date.Month,
                    MonthName = DataHelper.GetMonthName(date.Month),
                    Year = date.Year
                });
            }

            using (var client = new HttpClient())
            {
                Task.Run(() =>
                         {
                             try
                             {
                                 for (var startDate = fromDate; startDate < toDate; startDate = startDate.AddMonths(1))
                                 {
                                     var url = BuildUrl(credentials, startDate, startDate.AddMonths(1).AddDays(-1));
                                     var responseText = client.GetStringAsync(new Uri(url)).Result;
                                     var response = JObject.Parse(JsonConvert.SerializeXNode(XDocument.Parse(responseText)));
                                     var rowCount = JsonHelper.FromAttribute<decimal>(response["report"]["output"], "@rows", decimal.Zero);
                                     var rows = response["report"]["row"];
                                     
                                     if (rows != null)
                                     {
                                         var datarow = result.Details.First(sr => (sr.Month == startDate.Month) && (sr.Year == startDate.Year));

                                         if (rowCount > 1)
                                         {
                                             foreach (var row in rows)
                                             {
                                                 var val = 0m;

                                                 try
                                                 {
                                                     val = JsonHelper.FromAttribute<decimal>(row, "total_approved_commissions", decimal.Zero);
                                                 }
                                                 catch (Exception) {}
                                                 datarow.AffiliateRevenue += val;
                                             }
                                         }
                                         else
                                         {
                                             var val = 0m;

                                             try
                                             {
                                                 val = JsonHelper.FromAttribute<decimal>(rows, "total_approved_commissions", decimal.Zero);
                                             }
                                             catch (Exception) { }
                                             datarow.AffiliateRevenue += val;
                                         }
                                         datarow.GrossRevenue += datarow.AffiliateRevenue * 2;
                                     }
                                 }
                             }
                             catch (Exception e)
                             {
                                 _logger.ErrorException("GetSummaryData", e);
                             }
                         }).Wait();
            }
            //var res = result.Details.Select(d => d.MonthName + " " + d.AffiliateRevenue + " " + d.GrossRevenue).ToArray();
            return result;
        }