public static string FindBestInterestRate(Dictionary <string, LoanResponse> responses) { LoanResponse bestResponse = null; string bankName = ""; foreach (var response in responses) { if (bestResponse == null) { bestResponse = response.Value; bankName = response.Key; } else { if (response.Value.interestRate < bestResponse.interestRate) { bestResponse = response.Value; bankName = response.Key; } } } string returnString = "The best option for a loan is offered by: " + bankName + ", who offer an interest rate of: " + bestResponse.interestRate + "%"; return(returnString); }
public static LoanResponse GetResponseFromXML(string recievedResponse) { recievedResponse = recievedResponse.Replace("xmlns=\"http://tempuri.org/\"", ""); var serializer = new System.Xml.Serialization.XmlSerializer(typeof(LoanResponse)); using (TextReader reader = new StringReader(recievedResponse)) { LoanResponse handledRequest = (LoanResponse)serializer.Deserialize(reader); return(handledRequest); } }
public static LoanResponse GetResponseFromJSON(string recievedResponse) { DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(LoanResponse)); // Read string into memorystream first, so JSONSerializer can read it as bytes MemoryStream stream1 = new MemoryStream(); StreamWriter writer = new StreamWriter(stream1); writer.Write(recievedResponse); writer.Flush(); stream1.Position = 0; // Rest stream to first position, so we read from beginning. LoanResponse handledRequest = (LoanResponse)ser.ReadObject(stream1); return(handledRequest); }