public static async Task MainAsync() { CalculatorService = new CalculatorService("Https://DavidBewley.co.uk/api/"); Console.WriteLine($"Sending Alive Request: {await CalculatorService.GetAliveRequest()}"); Console.WriteLine($"Sending Echo Request (5): {await CalculatorService.GetEchoNumberRequest(5)}"); Console.WriteLine(); Console.WriteLine($"Sending Addition Request (5+12): {await CalculatorService.GetCalculationRequest(5, 12, CalculationType.Addition)}"); Console.WriteLine($"Sending Subtraction Request (10-2): {await CalculatorService.GetCalculationRequest(10, 2, CalculationType.Subtraction)}"); Console.WriteLine($"Sending Multiplication Request (9*2): {await CalculatorService.GetCalculationRequest(9, 2, CalculationType.Multiplication)}"); Console.WriteLine($"Sending Division Request (12/3): {await CalculatorService.GetCalculationRequest(12, 3, CalculationType.Divison)}"); Console.WriteLine(); Console.WriteLine($"Sending Get Calculation Request: "); Calculation calculation = await CalculatorService.GetCalculationProblem(); Console.WriteLine($"{calculation.Id}: {calculation.FirstNumber} {calculation.GetOperatorShortForm()} {calculation.SecondNumber}"); CalculationResponse response = await CalculatorService.GenerateCalculationResponse(calculation); Console.WriteLine($"Sending Solve Calculation Request (Answer: {response.Answer}): {await CalculatorService.PostCalculationResponse(response)}"); Console.ReadKey(); }
public List <CalculationResponse> CalculatePaymentPlan(CalculationRequest data) { //process the data and calculate the monthly payment double amount = data.Loan; var interestRatePerPeriod = (data.InterestRate / 100) / 12; var numbersOfPaymentPeriod = data.Years * 12; var monthlyPayment = Utility.CalculateMonhlyPayment.calculateMonhlyPayment(interestRatePerPeriod, numbersOfPaymentPeriod, amount); //Create payment plan List <CalculationResponse> paymentPlan = new List <CalculationResponse>(); var totalInterestPaid = 0.0; for (int i = 0; i < numbersOfPaymentPeriod; i++) { var interestAmount = amount * interestRatePerPeriod; totalInterestPaid += interestAmount; var downPayment = monthlyPayment - interestAmount; amount = amount - downPayment; CalculationResponse response = new CalculationResponse() { Month = i + 1, Interest = Math.Round(interestAmount, 2), Payment = Math.Round(monthlyPayment, 2), Principal = Math.Round(downPayment, 2), Balance = Math.Round(amount, 2), TotalInterestPaid = Math.Round(totalInterestPaid, 2) }; paymentPlan.Add(response); } return(paymentPlan); }
private void calculationResponseReceived(CalculationResponse response, Connection connection) { //5. CalculationResponse received. Console.WriteLine($"Answer received {response.Result}"); }
/// <summary> /// After calculation occurs in the calculation engine, provide a hook /// to perform additional custom actions. /// </summary> /// <param name="request">The request that was sent to the calculation engine.</param> /// <param name="response">The response that came back from the calculation engine.</param> /// <returns></returns> public ActionableResponse AfterCalculation(CalculationRequest request, CalculationResponse response) { // get values from named ranges of Excel file var name = request.Inputs.FirstOrDefault(x => x.Ref == "iName"); var mail = request.Inputs.FirstOrDefault(x => x.Ref == "iEmail"); // prepare the SOAP client BasicHttpBinding b = new BasicHttpBinding(); EndpointAddress ea = new EndpointAddress("https://login.salesforce.com/services/Soap/c/43.0"); b.Name = "Soap"; b.Namespace = "sforce.Soap"; b.Security.Mode = BasicHttpSecurityMode.Transport; SoapClient client = new SoapClient(b, ea); SessionHeader header; SoapClient apiClient; LoginResult loginResult; ActionableResponse ar = new ActionableResponse(); try { // authenticate to a Salesforce Web Service loginResult = client.login(null, accountName, accountPwd); header = new sforce.SessionHeader(); header.sessionId = loginResult.sessionId; EndpointAddress eaApiClient = new EndpointAddress(loginResult.serverUrl); // initialize API client apiClient = new SoapClient(b, eaApiClient); // create a Lead data Lead lead = new Lead() { // use same value for FirstName and LastName FirstName = name.Value[0][0].Value, LastName = name.Value[0][0].Value, Email = mail.Value[0][0].Value, Company = "Company Name", LeadSource = "Advertisement" }; AssignmentRuleHeader arh = new AssignmentRuleHeader(); QueryResult qr = null; LimitInfo[] li; SaveResult[] sr; // make an API request and add a Lead record to the Salesforce database apiClient.create( header, // sessionheader arh, // assignmentruleheader null, // mruheader null, // allowfieldtrunctionheader null, // disablefeedtrackingheader null, // streamingenabledheader null, // allornoneheader null, // duplicateruleheader null, // localeoptions null, // debuggingheader null, // packageversionheader null, // emailheader new sObject[] { lead }, out li, out sr); foreach (SaveResult s in sr) { if (s.success) { ar.Success = true; // for demonstration purpose we can set the id of added Lead record to a control visible on the page response.Outputs.FirstOrDefault(x => x.Ref == "Response").Value[0][0].Value = s.id; } else { // set error messages to send back to a page foreach (var e in s.errors) { ar.Messages.Add(e.message); } ar.Success = false; } } } catch (Exception ex) { // set error message to send back to a page ar.Messages.Add(ex.Message); ar.Success = false; } return(ar); }
private decimal CalculateAverage(CalculationResponse response) { return(response.TotalValue / response.ParcelCount); }
public ActionableResponse AfterCalculation(CalculationRequest request, CalculationResponse response) { var name = request.Inputs.FirstOrDefault(x => x.Ref == "iName"); var lastName = request.Inputs.FirstOrDefault(x => x.Ref == "iSurname"); var cardNumber = request.Inputs.FirstOrDefault(x => x.Ref == "iCardNumber"); var year = request.Inputs.FirstOrDefault(x => x.Ref == "iYear"); var month = request.Inputs.FirstOrDefault(x => x.Ref == "iMonth"); var cvc = request.Inputs.FirstOrDefault(x => x.Ref == "iCVC"); var amount = Convert.ToDecimal(request.Inputs.FirstOrDefault(x => x.Ref == "iAmount").Value[0][0].Value); var address = request.Inputs.FirstOrDefault(x => x.Ref == "iAddress"); var city = request.Inputs.FirstOrDefault(x => x.Ref == "iCity"); var zip = request.Inputs.FirstOrDefault(x => x.Ref == "iZip"); var errRespo = new ActionableResponse(); errRespo.Success = false; errRespo.ResponseAction = ResponseAction.Cancel; errRespo.Messages = new System.Collections.Generic.List <string>(); try { ApiOperationBase <ANetApiRequest, ANetApiResponse> .RunEnvironment = AuthorizeNet.Environment.SANDBOX; ApiOperationBase <ANetApiRequest, ANetApiResponse> .MerchantAuthentication = new merchantAuthenticationType() { name = apiLoginId, ItemElementName = ItemChoiceType.transactionKey, Item = transactionKey, }; var creditCard = new creditCardType { cardNumber = cardNumber.Value[0][0].Value, expirationDate = month.Value[0][0].Value + year.Value[0][0].Value, cardCode = cvc.Value[0][0].Value }; var billingAddress = new customerAddressType { firstName = name.Value[0][0].Value, lastName = lastName.Value[0][0].Value, address = address.Value[0][0].Value, city = city.Value[0][0].Value, zip = zip.Value[0][0].Value }; var paymentType = new paymentType { Item = creditCard }; // Add line Items var lineItems = new lineItemType[2]; lineItems[0] = new lineItemType { itemId = "1", name = "t-shirt", quantity = 2, unitPrice = new Decimal(15.00) }; lineItems[1] = new lineItemType { itemId = "2", name = "snowboard", quantity = 1, unitPrice = new Decimal(450.00) }; var transactionRequest = new transactionRequestType { transactionType = transactionTypeEnum.authCaptureTransaction.ToString(), // charge the card amount = amount, payment = paymentType, billTo = billingAddress, lineItems = lineItems }; var req = new createTransactionRequest { transactionRequest = transactionRequest }; var controller = new createTransactionController(req); controller.Execute(); var resp = controller.GetApiResponse(); if (resp != null) { if (resp.messages.resultCode == messageTypeEnum.Ok) { if (resp.transactionResponse.messages != null) { response.Outputs.FirstOrDefault(x => x.Ref == "oResponse").Value[0][0].Value = "Successfully created transaction with Transaction ID: " + resp.transactionResponse.transId + "<br />" + "Response Code: " + resp.transactionResponse.responseCode + "<br />" + "Message Code: " + resp.transactionResponse.messages[0].code + "<br />" + "Description: " + resp.transactionResponse.messages[0].description + "<br />" + "Success, Auth Code : " + resp.transactionResponse.authCode; return(new ActionableResponse { Success = true }); } else { errRespo.Messages.Add("Failed Transaction."); if (resp.transactionResponse.errors != null) { errRespo.Messages.Add("Error Code: " + resp.transactionResponse.errors[0].errorCode); errRespo.Messages.Add("Error message: " + resp.transactionResponse.errors[0].errorText); } return(errRespo); } } else { errRespo.Messages.Add("Failed Transaction."); if (resp.transactionResponse != null && resp.transactionResponse.errors != null) { errRespo.Messages.Add("Error Code: " + resp.transactionResponse.errors[0].errorCode); errRespo.Messages.Add("Error message: " + resp.transactionResponse.errors[0].errorText); } else { errRespo.Messages.Add("Error Code: " + resp.messages.message[0].code); errRespo.Messages.Add("Error message: " + resp.messages.message[0].text); } return(errRespo); } } else { errRespo.Messages.Add("Null Response."); } return(errRespo); } catch (Exception ex) { return(new ActionableResponse { Success = false, Messages = new System.Collections.Generic.List <string>() { ex.Message }, ResponseAction = ResponseAction.Cancel }); } }