public static GetCustomerRankQualificationsResponse GetCustomerRankQualifications(GetCustomerRankQualificationsRequest request) { // Get the rank qualifications from the API var apiResponse = new GetRankQualificationsResponse(); try { var apiRequest = new GetRankQualificationsRequest { CustomerID = request.CustomerID, PeriodType = request.PeriodTypeID }; if (request.RankID != null) { apiRequest.RankID = (int)request.RankID; } apiResponse = Exigo.WebService().GetRankQualifications(apiRequest); } catch (Exception ex) { return(new GetCustomerRankQualificationsResponse() { IsUnavailable = ex.Message.ToUpper() == "UNAVAILABLE", ErrorMessage = ex.Message }); } // Create the response var response = new GetCustomerRankQualificationsResponse() { TotalPercentComplete = apiResponse.Score, IsQualified = (apiResponse.Qualifies || (apiResponse.QualifiesOverride != null && ((bool)apiResponse.QualifiesOverride) == true)), Rank = new Rank() { RankID = apiResponse.RankID, RankDescription = apiResponse.RankDescription } }; if (apiResponse.BackRankID != null) { response.PreviousRank = new Rank() { RankID = (int)apiResponse.BackRankID, RankDescription = apiResponse.BackRankDescription }; } if (apiResponse.NextRankID != null) { response.NextRank = new Rank() { RankID = (int)apiResponse.NextRankID, RankDescription = apiResponse.NextRankDescription }; } // Loop through each leg and create our responses var legs = new List <RankQualificationLeg>(); foreach (var qualificationLeg in apiResponse.PayeeQualificationLegs) { var leg = new RankQualificationLeg(); // Assemble the requirements var results = new List <RankRequirement>(); foreach (var definition in Definitions) { var requirement = GetRequirement(qualificationLeg, definition); if (requirement != null) { requirement.RequirementDescription = GlobalUtilities.MergeFields(requirement.RequirementDescription, requirement, "UNABLE TO MERGE FIELDS"); requirement.QualifiedDescription = GlobalUtilities.MergeFields(requirement.QualifiedDescription, requirement, "UNABLE TO MERGE FIELDS"); requirement.NotQualifiedDescription = GlobalUtilities.MergeFields(requirement.NotQualifiedDescription, requirement, "UNABLE TO MERGE FIELDS"); results.Add(requirement); } } // Clean up nulls results.RemoveAll(c => string.IsNullOrEmpty(c.RequiredValue)); leg.Requirements = results; legs.Add(leg); } response.QualificationLegs = legs; return(response); }
public static GetCustomerRankQualificationsResponse GetCustomerRankQualifications(GetCustomerRankQualificationsRequest request) { // Get the rank qualifications from the API var apiResponse = new GetRankQualificationsResponse(); try { var apiRequest = new GetRankQualificationsRequest { CustomerID = request.CustomerID, PeriodType = request.PeriodTypeID }; if (request.RankID != null) apiRequest.RankID = (int)request.RankID; apiResponse = Exigo.WebService().GetRankQualifications(apiRequest); if(apiResponse == null || apiResponse.RankID == 0) { return new GetCustomerRankQualificationsResponse() { IsUnavailable = true, ErrorMessage = "UNAVAILABLE" }; } } catch(Exception exception) { return new GetCustomerRankQualificationsResponse() { IsUnavailable = exception.Message.ToUpper().Contains("UNAVAILABLE"), ErrorMessage = exception.Message }; } // Create the response var response = new GetCustomerRankQualificationsResponse() { TotalPercentComplete = apiResponse.Score, IsQualified = (apiResponse.Qualifies || (apiResponse.QualifiesOverride != null && ((bool)apiResponse.QualifiesOverride) == true)), Rank = new Rank() { RankID = apiResponse.RankID, RankDescription = apiResponse.RankDescription } }; if (apiResponse.BackRankID != null) { response.PreviousRank = new Rank() { RankID = (int)apiResponse.BackRankID, RankDescription = apiResponse.BackRankDescription }; } if (apiResponse.NextRankID != null) { response.NextRank = new Rank() { RankID = (int)apiResponse.NextRankID, RankDescription = apiResponse.NextRankDescription }; } // Loop through each leg and create our responses var legs = new List<RankQualificationLeg>(); foreach (var qualificationLeg in apiResponse.PayeeQualificationLegs) { var leg = new RankQualificationLeg(); // Assemble the requirements var results = new List<RankRequirement>(); foreach (var definition in RankQualificationDefinitions) { var requirement = GetRequirement(qualificationLeg, definition); if (requirement != null) { requirement.RequirementDescription = GlobalUtilities.MergeFields(requirement.RequirementDescription, requirement, "UNABLE TO MERGE FIELDS"); requirement.QualifiedDescription = GlobalUtilities.MergeFields(requirement.QualifiedDescription, requirement, "UNABLE TO MERGE FIELDS"); requirement.NotQualifiedDescription = GlobalUtilities.MergeFields(requirement.NotQualifiedDescription, requirement, "UNABLE TO MERGE FIELDS"); results.Add(requirement); } } // Clean up nulls results.RemoveAll(c => string.IsNullOrEmpty(c.RequiredValue)); leg.Requirements = results; legs.Add(leg); } response.QualificationLegs = legs; return response; }