Advertisement
Guest User

Untitled

a guest
Jul 17th, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. using System;
  2.  
  3. using System.Net;
  4.  
  5. using System.Net.Http;
  6.  
  7. using System.Threading.Tasks;
  8.  
  9. using Microsoft.Azure.WebJobs;
  10.  
  11. using Microsoft.Azure.WebJobs.Host;
  12.  
  13. public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log)
  14.  
  15. {
  16.  
  17. log.Info("Calculating EMI");
  18.  
  19. dynamic data = await req.Content.ReadAsAsync<object>();
  20.  
  21. string years = data?.years;
  22.  
  23. log.Info($"Getting Loan year as {years}");
  24.  
  25. string loan = data?.loan;
  26.  
  27. log.Info($"Getting Loan amount as {loan}");
  28.  
  29. string Rate = data?.rate;
  30.  
  31. log.Info($"Getting Loan rate as {Rate}");
  32.  
  33. double InterestRate = Convert.ToDouble(Rate);
  34.  
  35. double PaymentPeriods = Convert.ToInt16(Convert.ToDouble(years) * 12);
  36.  
  37. double LoanAmount = Convert.ToDouble(loan);
  38.  
  39. if (InterestRate > 1)
  40.  
  41. {
  42.  
  43. InterestRate = InterestRate / 100;
  44.  
  45. }
  46.  
  47. double Payment = (LoanAmount * Math.Pow((InterestRate / 12) + 1,
  48.  
  49. (PaymentPeriods)) * InterestRate / 12) / (Math.Pow
  50.  
  51. (InterestRate / 12 + 1, (PaymentPeriods)) - 1);
  52.  
  53. //double EMI = (emiloan * emiinterestRate)/(100 * 12);
  54.  
  55. return Payment == 0
  56.  
  57. ? req.CreateResponse(HttpStatusCode.BadRequest, "Please pass a name on the query string or in the request body")
  58.  
  59. : req.CreateResponse(HttpStatusCode.OK,Payment.ToString("N2") );
  60.  
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement