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;
        }
예제 #2
0
        public ActionResult LogOn()
        {
            var model = new ClientAuthenticationViewModel();

            if (TempData["failedModel"] != null)
            {
                var contents = TempData["failedModel"] as ClientAuthenticationViewModel;
                model = contents;
            }

            return View(model);
        }
        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;
        }
예제 #4
0
        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;
        }
예제 #5
0
 private static string BuildUrl(ClientAuthenticationViewModel credentials, DateTime fromDate, DateTime toDate)
 {
     return string.Format(EarningssReportUrl, credentials.MarketAffiliateId, credentials.MarketApiKey, fromDate.ToString("yyyy-MM-dd"), toDate.ToString("yyyy-MM-dd"));
 }
예제 #6
0
        public ActionResult LogOn(ClientAuthenticationViewModel user, string ReturnUrl)
        {
            var authResult = _authenticationService.AuthenticateUser(user.UserName, user.Password, Request.UserHostAddress);

            if (authResult.InvalidCredentials)
            {
                TempData["failedModel"] = user;
                TempData["CommandFail"] = authResult.ErrorMessages;

                if (authResult.HasValidationMessages)
                {
                    TempData["CommandFail"] += authResult.ValidationMessages;
                }

                return RedirectToAction("LogOn");
            }

            //
            // Notes:
            //  For now both failures will be reported with the same message and behavior.
            Func<RedirectToRouteResult> invalidAffiliateId = () =>
            {
                TempData["failedModel"] = user;
                TempData["CommandFail"] = "The login is valid but is not associated with an Affiliate Id";

                return RedirectToAction("LogOn");
            };

            if (authResult.InvalidAffiliate)
            {
                return invalidAffiliateId();
            }

            var clientKey = DataHelper.GetClientKey(authResult.MarketAffiliateId.Value);

            if (clientKey == null)
            {
                return invalidAffiliateId();
            }

            try
            {
                this.SetAuthToken
                (
                    _configurationProvider.CookieAuthName,
                    DateTime.Now.Add(_configurationProvider.CookieDurationTime),
                    new Tuple<string, string>[]
                    {
                        Tuple.Create(_configurationProvider.CookieLoginToken, authResult.Token),
                        Tuple.Create(_configurationProvider.CookieLoginUsername, user.UserName),
                        Tuple.Create(_configurationProvider.CookieLoginAffiliateId, authResult.MarketAffiliateId.ToString()),
                        Tuple.Create("ClientKeyId", clientKey.ToString())
                    }
                );

                // redirect back to the originally requested page or the default page
                if (!string.IsNullOrWhiteSpace(ReturnUrl))
                {
                    return Redirect(ReturnUrl);
                }
            }
            catch
            {
                this.ClearAuthToken(_configurationProvider.CookieAuthName);
            }

            return RedirectToAction("Index", "Home");
        }