public static HttpResponseMessage addbook(HttpRequestMessage req, [HttpTrigger] AddBookRequest parameters, [SQLDatabase(ConnectionString = "ConnectionString", TableName = "Book", SQLQuery = "")] ICollector <string> output, TraceWriter log) { // Validate/default parameters if (string.IsNullOrEmpty(parameters.title)) { parameters.title = "Noname-" + System.Guid.NewGuid().ToString(); } if (string.IsNullOrEmpty(parameters.author)) { parameters.author = null; } if (string.IsNullOrEmpty(parameters.yr)) { parameters.yr = null; } if (string.IsNullOrEmpty(parameters.genre)) { parameters.genre = null; } // Create data table JSON for output string json = @"[ { ""Title"": """ + parameters.title + @""", ""Author"": """ + parameters.author + @""", ""Yr"": """ + parameters.yr + @""", ""Genre"": """ + parameters.genre + @""" } ]"; output.Add(json); return(req.CreateResponse(HttpStatusCode.Created)); }
public static HttpResponseMessage addbook(HttpRequestMessage req, [HttpTrigger] AddBookRequest parameters, [SQLDatabase(ConnectionString = "ConnectionString", TableName = "Book")] ICollector <DataTable> output, TraceWriter log) { // Validate/default parameters if (string.IsNullOrEmpty(parameters.title)) { parameters.title = "Noname-" + System.Guid.NewGuid().ToString(); } if (string.IsNullOrEmpty(parameters.author)) { parameters.author = null; } if (string.IsNullOrEmpty(parameters.yr)) { parameters.yr = null; } if (string.IsNullOrEmpty(parameters.genre)) { parameters.genre = null; } // Create data table for output DataTable table = new DataTable(); table.TableName = "Book"; table.Clear(); table.Columns.Add("Title"); table.Columns.Add("Author"); table.Columns.Add("Yr"); table.Columns.Add("Genre"); DataRow row = table.NewRow(); row["Title"] = parameters.title; row["Author"] = parameters.author; row["Yr"] = parameters.yr; row["Genre"] = parameters.genre; table.Rows.Add(row); output.Add(table); return(req.CreateResponse(HttpStatusCode.Created)); }