EbarriosCode / Xamarin-Azure-Functions

Demo Dotnet Conf on Focus Xamarin 2020

Home Page:https://docs.google.com/presentation/d/198u-9aRsPR6WH-kQj7ytGImzjlF3kiZkM5IUkl-Bcqo/edit#slide=id.g7f53659729_0_0

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Xamarin-Azure-Functions

Código Azure Function

#r "Newtonsoft.Json"

using System.Net;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Primitives;
using Newtonsoft.Json;

public static async Task<IActionResult> Run(HttpRequest req, ILogger log)
{
    log.LogInformation("C# HTTP trigger function procesando petición.");    

    string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
    dynamic data = JsonConvert.DeserializeObject(requestBody);    
    
    if(data != null)
    {
        double peso = Convert.ToDouble(data.peso);
        double altura = Convert.ToDouble(data.altura);
        double result = (peso/(altura * altura));        
        
        return (ActionResult)new OkObjectResult(new { Result = Math.Truncate(result)});
    }
    else
        return new BadRequestObjectResult("Por favor envie un nombre, altura en metros y peso en kilogramos en el cuerpo de la solicitud");     
}