public JsonNetResult GetRealTimeBonusDetails(KendoGridRequest request) { try { // Have to include this as part of the url via a query string, to avoid hacking the kendo request object that is Http POSTed - Mike M. var periodID = Request.QueryString["periodID"] != null?Convert.ToInt32(Request.QueryString["periodID"]) : 0; var results = new List <RealTimeCommissionBonusDetail>(); // Get the commission record(s) var context = ExigoDAL.WebService(); var realtimeresponse = context.GetRealTimeCommissions(new Common.Api.ExigoWebService.GetRealTimeCommissionsRequest { CustomerID = Identity.Current.CustomerID }); if (realtimeresponse.Commissions.Length == 0) { return(new JsonNetResult()); } // Get the bonuses (I know, this is brutal, but our UI depends on it) var commissionsList = periodID > 0 ? realtimeresponse.Commissions.Where(c => c.PeriodID == periodID).ToList() : realtimeresponse.Commissions.ToList(); foreach (var commission in commissionsList) { var bonuses = commission.Bonuses .Select(c => new CommissionBonus() { BonusID = c.BonusID, BonusDescription = c.Description }).Distinct(); foreach (var bonusID in commission.Bonuses.Select(c => c.BonusID).Distinct()) { var bonus = bonuses.Where(c => c.BonusID == bonusID).FirstOrDefault(); // Get the details for this bonus var details = context.GetRealTimeCommissionDetail(new Common.Api.ExigoWebService.GetRealTimeCommissionDetailRequest { CustomerID = commission.CustomerID, PeriodType = commission.PeriodType, PeriodID = commission.PeriodID, BonusID = bonusID }).CommissionDetails; // Get the period details for this period var period = ExigoDAL.GetPeriods(new GetPeriodsRequest { PeriodTypeID = commission.PeriodType, PeriodIDs = new List <int> { commission.PeriodID } }).FirstOrDefault(); // Format and save each bonus foreach (var detail in details) { var typedDetail = (CommissionBonusDetail)detail; var result = GlobalUtilities.Extend(typedDetail, new RealTimeCommissionBonusDetail()); result.BonusID = bonus.BonusID; result.BonusDescription = bonus.BonusDescription; result.PeriodDescription = period.PeriodDescription; results.Add(result); } } } // Filtering foreach (var filter in request.FilterObjectWrapper.FilterObjects) { results = results.AsQueryable().Where(filter.Field1, filter.Operator1, filter.Value1).ToList(); } // Sorting foreach (var sort in request.SortObjects) { results = results.AsQueryable().OrderBy(sort.Field, sort.Direction).ToList(); } // Return the data return(new JsonNetResult(new { data = results })); } catch (Exception ex) { return(new JsonNetResult(new { success = false, message = ex.Message })); } }