Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Net;
- using System.Net.Http;
- using System.Threading.Tasks;
- using Microsoft.Azure.WebJobs;
- using Microsoft.Azure.WebJobs.Host;
- public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log)
- {
- log.Info("Calculating EMI");
- dynamic data = await req.Content.ReadAsAsync<object>();
- string years = data?.years;
- log.Info($"Getting Loan year as {years}");
- string loan = data?.loan;
- log.Info($"Getting Loan amount as {loan}");
- string Rate = data?.rate;
- log.Info($"Getting Loan rate as {Rate}");
- double InterestRate = Convert.ToDouble(Rate);
- double PaymentPeriods = Convert.ToInt16(Convert.ToDouble(years) * 12);
- double LoanAmount = Convert.ToDouble(loan);
- if (InterestRate > 1)
- {
- InterestRate = InterestRate / 100;
- }
- double Payment = (LoanAmount * Math.Pow((InterestRate / 12) + 1,
- (PaymentPeriods)) * InterestRate / 12) / (Math.Pow
- (InterestRate / 12 + 1, (PaymentPeriods)) - 1);
- //double EMI = (emiloan * emiinterestRate)/(100 * 12);
- return Payment == 0
- ? req.CreateResponse(HttpStatusCode.BadRequest, "Please pass a name on the query string or in the request body")
- : req.CreateResponse(HttpStatusCode.OK,Payment.ToString("N2") );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement