public static IEnumerable <RealTimeCommission> GetCustomerRealTimeCommissions(GetCustomerRealTimeCommissionsRequest request) { var results = new List <RealTimeCommission>(); // Get the commission record var realtimeresponse = Exigo.WebService().GetRealTimeCommissions(new Common.Api.ExigoWebService.GetRealTimeCommissionsRequest { CustomerID = request.CustomerID }); if (realtimeresponse.Commissions.Length == 0) { return(results); } // Get the unique periods for each of the commission results var periods = new List <Period>(); var periodRequests = new List <GetPeriodsRequest>(); foreach (var commissionResponse in realtimeresponse.Commissions) { var periodID = commissionResponse.PeriodID; var periodTypeID = commissionResponse.PeriodType; var req = periodRequests.Where(c => c.PeriodTypeID == periodTypeID).FirstOrDefault(); if (req == null) { periodRequests.Add(new GetPeriodsRequest() { PeriodTypeID = periodTypeID, PeriodIDs = new int[] { periodID } }); } else { var ids = req.PeriodIDs.ToList(); ids.Add(periodID); req.PeriodIDs = ids.Distinct().ToArray(); } } periodRequests.ForEach(s => GetPeriods(s).ToList().ForEach(a => periods.Add(a))); //replaced the below loops with above line. //foreach (var req in periodRequests) //{ // var responses = GetPeriods(req); // foreach (var response in responses) // { // periods.Add(response); // } //} // Process each commission response try { foreach (var commission in realtimeresponse.Commissions) { var typedCommission = (RealTimeCommission)commission; typedCommission.Period = periods .Where(c => c.PeriodID == commission.PeriodID && c.PeriodTypeID == commission.PeriodType) .FirstOrDefault(); //typedCommission.Period = periods // .Where(c => c.PeriodTypeID == commission.PeriodType) // .Where(c => c.PeriodID == commission.PeriodID) // .FirstOrDefault(); bool isPeriodMonthly = typedCommission.Period.PeriodTypeID == PeriodTypes.Monthly; GetCustomerVolumesRequest getCustomerVolumesRequest = new GetCustomerVolumesRequest { CustomerID = request.CustomerID, PeriodID = typedCommission.Period.PeriodID, PeriodTypeID = PeriodTypes.Monthly, VolumeIDs = request.VolumeIDs }; if (!isPeriodMonthly) { getCustomerVolumesRequest.PeriodID = null; getCustomerVolumesRequest.ReportForMonth = typedCommission.Period.EndDate;// period.EndDate; } typedCommission.Volumes = GetCustomerVolumes(getCustomerVolumesRequest); typedCommission.PaidRank = typedCommission.Volumes.PayableAsRank; results.Add(typedCommission); } return(results.OrderByDescending(c => c.Period.StartDate)); } catch { return(results); } }
public static IEnumerable <RealTimeCommission> GetCustomerRealTimeCommissions(GetCustomerRealTimeCommissionsRequest request) { var results = new List <RealTimeCommission>(); // Get the commission record var realtimeresponse = Exigo.WebService().GetRealTimeCommissions(new Common.Api.ExigoWebService.GetRealTimeCommissionsRequest { CustomerID = request.CustomerID }); if (realtimeresponse.Commissions.Length == 0) { return(results); } // Get the unique periods for each of the commission results var periods = new List <Period>(); var periodRequests = new List <GetPeriodsRequest>(); foreach (var commissionResponse in realtimeresponse.Commissions) { var periodID = commissionResponse.PeriodID; var periodTypeID = commissionResponse.PeriodType; var req = periodRequests.Where(c => c.PeriodTypeID == periodTypeID).FirstOrDefault(); if (req == null) { periodRequests.Add(new GetPeriodsRequest() { PeriodTypeID = periodTypeID, PeriodIDs = new int[] { periodID } }); } else { var ids = req.PeriodIDs.ToList(); ids.Add(periodID); req.PeriodIDs = ids.Distinct().ToArray(); } } foreach (var req in periodRequests) { var responses = GetPeriods(req); foreach (var response in responses) { periods.Add(response); } } // Get the volumes for each unique period var volumeCollections = new List <VolumeCollection>(); foreach (var period in periods) { volumeCollections.Add(GetCustomerVolumes(new GetCustomerVolumesRequest { CustomerID = request.CustomerID, PeriodID = period.PeriodID, PeriodTypeID = period.PeriodTypeID, VolumeIDs = request.VolumeIDs })); } // Process each commission response foreach (var commission in realtimeresponse.Commissions) { var typedCommission = (RealTimeCommission)commission; typedCommission.Period = periods .Where(c => c.PeriodTypeID == commission.PeriodType) .Where(c => c.PeriodID == commission.PeriodID) .FirstOrDefault(); typedCommission.Volumes = volumeCollections .Where(c => c.Period.PeriodTypeID == typedCommission.Period.PeriodTypeID) .Where(c => c.Period.PeriodID == typedCommission.Period.PeriodID) .FirstOrDefault(); typedCommission.PaidRank = typedCommission.Volumes.PayableAsRank; results.Add(typedCommission); } return(results.OrderByDescending(c => c.Period.StartDate)); }
public static IEnumerable<RealTimeCommission> GetCustomerRealTimeCommissions(GetCustomerRealTimeCommissionsRequest request) { var results = new List<RealTimeCommission>(); // Get the commission record var realtimeresponse = Exigo.WebService().GetRealTimeCommissions(new Common.Api.ExigoWebService.GetRealTimeCommissionsRequest { CustomerID = request.CustomerID }); if (realtimeresponse.Commissions.Length == 0) return results; // Get the unique periods for each of the commission results var periods = new List<Period>(); var periodRequests = new List<GetPeriodsRequest>(); foreach (var commissionResponse in realtimeresponse.Commissions) { var periodID = commissionResponse.PeriodID; var periodTypeID = commissionResponse.PeriodType; var req = periodRequests.Where(c => c.PeriodTypeID == periodTypeID).FirstOrDefault(); if (req == null) { periodRequests.Add(new GetPeriodsRequest() { PeriodTypeID = periodTypeID, PeriodIDs = new int[] { periodID } }); } else { var ids = req.PeriodIDs.ToList(); ids.Add(periodID); req.PeriodIDs = ids.Distinct().ToArray(); } } foreach (var req in periodRequests) { var responses = GetPeriods(req); foreach (var response in responses) { periods.Add(response); } } // Get the volumes for each unique period var volumeCollections = new List<VolumeCollection>(); foreach (var period in periods) { volumeCollections.Add(GetCustomerVolumes(new GetCustomerVolumesRequest { CustomerID = request.CustomerID, PeriodID = period.PeriodID, PeriodTypeID = period.PeriodTypeID, VolumeIDs = request.VolumeIDs })); } // Process each commission response try { foreach (var commission in realtimeresponse.Commissions) { var typedCommission = (RealTimeCommission)commission; typedCommission.Period = periods .Where(c => c.PeriodTypeID == commission.PeriodType) .Where(c => c.PeriodID == commission.PeriodID) .FirstOrDefault(); typedCommission.Volumes = volumeCollections .Where(c => c.Period.PeriodTypeID == typedCommission.Period.PeriodTypeID) .Where(c => c.Period.PeriodID == typedCommission.Period.PeriodID) .FirstOrDefault(); typedCommission.PaidRank = typedCommission.Volumes.PayableAsRank; results.Add(typedCommission); } return results.OrderByDescending(c => c.Period.StartDate); } catch { return results; } }