Skip to content

Instantly share code, notes, and snippets.

@johndowns
Created December 5, 2018 21:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johndowns/57dbcea7ebbe1ce12096b4a38ea13bb5 to your computer and use it in GitHub Desktop.
Save johndowns/57dbcea7ebbe1ce12096b4a38ea13bb5 to your computer and use it in GitHub Desktop.
#r "Newtonsoft.Json"
using System.Net;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Primitives;
using Newtonsoft.Json;
static Random Random = new Random();
public static async Task<IActionResult> Run(HttpRequest req, ILogger log)
{
string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
var shippingDetails = JsonConvert.DeserializeObject<ShippingDetails>(requestBody);
var shippingCost = CalculateShippingCost(shippingDetails);
return (ActionResult)new OkObjectResult(shippingCost);
}
public static ShippingCost CalculateShippingCost(ShippingDetails shippingDetails)
{
// simulating doing important calculations...
return new ShippingCost
{
Cost = (decimal)Random.NextDouble() * 50
};
}
public class ShippingDetails
{
public decimal PackageWidth { get; set; }
public decimal PackageHeight { get; set; }
public decimal PackageDepth { get; set; }
public decimal PackageWeight { get; set; }
public string RecipientPostCode { get; set; }
}
public class ShippingCost
{
public decimal Cost { get; set; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment