Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #r "Newtonsoft.Json"
- using System.Net;
- using System.Linq;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.Extensions.Primitives;
- using Newtonsoft.Json;
- public class AuctionItem
- {
- [JsonProperty("itemID")]
- public string itemID { get; set; }
- [JsonProperty("price")]
- public string Price { get; set; }
- [JsonProperty("amount")]
- public string Amount { get; set; }
- }
- public static IActionResult Run(HttpRequest req, out object outputDocument,
- IEnumerable<AuctionItem> inputDocument, ILogger log)
- {
- log.LogInformation("C# HTTP trigger function processed a request.");
- string name = req.Query["name"];
- string price = req.Query["price"];
- string amount = req.Query["amount"];
- string command = req.Query["command"];
- outputDocument = null;
- if (!string.IsNullOrEmpty(name) && !string.IsNullOrEmpty(price) && !string.IsNullOrEmpty(amount)) {
- string responseMessage = "{\"Message\":\"Success\",\n\"Data\": [" + "\n";
- if (!string.IsNullOrEmpty(command)) {
- if (command == "1") {
- foreach (var item in inputDocument) {
- responseMessage += "{\n\t\"itemID\":\"" + item.itemID + "\"," + "\n";
- responseMessage += "\t\"price\":\"" + item.Price + "\"," + "\n";
- responseMessage += "\t\"amount\":\"" + item.Amount + "\"}," + "\n";
- }
- } else if (command == "2") {
- var item = inputDocument.Where(x => x.itemID == name).FirstOrDefault();
- if (item != null) {
- inputDocument = inputDocument.Where(x => x != item);
- }
- } else if (command == "3") {
- responseMessage += "{\n\t\"itemID\":\"" + name + "\",\n";
- responseMessage += "\t\"price\":\"" + price + "\",\n";
- responseMessage += "\t\"amount\":\"" + amount + "\"}\n";
- log.LogInformation(responseMessage);
- outputDocument = new {
- itemID = name,
- price = price,
- amount = amount
- };
- }
- }
- responseMessage += "]}";
- return new OkObjectResult(responseMessage);
- } else {
- outputDocument = null;
- return new BadRequestResult();
- }
- }
Add Comment
Please, Sign In to add comment