-
-
Save johndowns/57dbcea7ebbe1ce12096b4a38ea13bb5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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