diff --git a/samples/databases/wide-world-importers/wwi-app/Controllers/ODataController.cs b/samples/databases/wide-world-importers/wwi-app/Controllers/ODataController.cs index de928a88..436eb258 100644 --- a/samples/databases/wide-world-importers/wwi-app/Controllers/ODataController.cs +++ b/samples/databases/wide-world-importers/wwi-app/Controllers/ODataController.cs @@ -20,7 +20,7 @@ namespace wwi_app.Controllers } - TableSpec salesorders = new TableSpec("WebApi","SalesOrders", "OrderID,OrderDate,CustomerPurchaseOrderNumber,ExpectedDeliveryDate,PickingCompletedWhen,CustomerID,CustomerName,PhoneNumber,FaxNumber,WebsiteURL,DeliveryLocation,SalesPerson,SalesPersonPhone,SalesPersonEmail"); + TableSpec salesorders = new TableSpec(schema: "WebApi", table: "SalesOrders", columns: "OrderID,OrderDate,CustomerPurchaseOrderNumber,ExpectedDeliveryDate,PickingCompletedWhen,CustomerID,CustomerName,PhoneNumber,FaxNumber,WebsiteURL,DeliveryLocation,SalesPerson,SalesPersonPhone,SalesPersonEmail"); [HttpGet] public async Task SalesOrders(int? id) diff --git a/samples/databases/wide-world-importers/wwi-app/wwi-app.csproj b/samples/databases/wide-world-importers/wwi-app/wwi-app.csproj index 266181e1..450eceed 100644 --- a/samples/databases/wide-world-importers/wwi-app/wwi-app.csproj +++ b/samples/databases/wide-world-importers/wwi-app/wwi-app.csproj @@ -27,7 +27,7 @@ - + diff --git a/samples/databases/wide-world-importers/wwi-azure-functions/Customers.cs b/samples/databases/wide-world-importers/wwi-azure-functions/Customers.cs deleted file mode 100644 index d837cf83..00000000 --- a/samples/databases/wide-world-importers/wwi-azure-functions/Customers.cs +++ /dev/null @@ -1,32 +0,0 @@ -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Mvc; -using Microsoft.Azure.WebJobs; -using Microsoft.Azure.WebJobs.Extensions.Http; -using Microsoft.Extensions.Logging; -using MsSql.RestApi; -using System; -using System.Threading.Tasks; - -namespace wwi_azure_functions -{ - public static class Customers - { - [FunctionName("Customers")] - public static async Task Run( - [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = null)] HttpRequest req, ILogger log) - { - log.LogInformation("C# HTTP trigger function processed a request."); - - try - { - TableSpec customers = new TableSpec("WebApi", "Customers", "CustomerID,CustomerName,AccountOpenedDate,CustomerCategoryName,PrimaryContact,AlternateContact,PhoneNumber,FaxNumber,WebsiteURL,PostalAddressLine1,PostalAddressLine2,PostalCity,PostalCityID,PostalPostalCode,CreditLimit,IsOnCreditHold,IsStatementSent,PaymentDays,RunPosition,StandardDiscountPercentage,BuyingGroupName,DeliveryLocation,BuyingGroupID,BillToCustomerID,CustomerCategoryID,PrimaryContactPersonID,AlternateContactPersonID"); - return await req.OData(customers).GetResult(Environment.GetEnvironmentVariable("SqlDb")); - } - catch (Exception ex) - { - log.LogError($"C# Http trigger function exception: {ex.Message}"); - return new StatusCodeResult(500); - } - } - } -} diff --git a/samples/databases/wide-world-importers/wwi-azure-functions/Invoices.cs b/samples/databases/wide-world-importers/wwi-azure-functions/Invoices.cs deleted file mode 100644 index e3da9bf7..00000000 --- a/samples/databases/wide-world-importers/wwi-azure-functions/Invoices.cs +++ /dev/null @@ -1,32 +0,0 @@ -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Mvc; -using Microsoft.Azure.WebJobs; -using Microsoft.Azure.WebJobs.Extensions.Http; -using Microsoft.Extensions.Logging; -using MsSql.RestApi; -using System; -using System.Threading.Tasks; - -namespace wwi_azure_functions -{ - public static class Invoices - { - [FunctionName("Invoices")] - public static async Task Run( - [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = null)] HttpRequest req, ILogger log) - { - log.LogInformation("C# HTTP trigger function processed a request."); - - try - { - TableSpec invoices = new TableSpec("WebApi", "Invoices", "InvoiceID,InvoiceDate,CustomerPurchaseOrderNumber,IsCreditNote,TotalDryItems,TotalChillerItems,DeliveryRun,RunPosition,ReturnedDeliveryData,ConfirmedDeliveryTime,ConfirmedReceivedBy,CustomerName,SalesPersonName,ContactName,ContactPhone,ContactEmail,SalesPersonEmail,DeliveryMethodName,CustomerID,OrderID,DeliveryMethodID,ContactPersonID,AccountsPersonID,SalespersonPersonID,PackedByPersonID"); - return await req.OData(invoices).GetResult(Environment.GetEnvironmentVariable("SqlDb")); - } - catch (Exception ex) - { - log.LogError($"C# Http trigger function exception: {ex.Message}"); - return new StatusCodeResult(500); - } - } - } -} diff --git a/samples/databases/wide-world-importers/wwi-azure-functions/ODataFunctions.cs b/samples/databases/wide-world-importers/wwi-azure-functions/ODataFunctions.cs new file mode 100644 index 00000000..1c378c9a --- /dev/null +++ b/samples/databases/wide-world-importers/wwi-azure-functions/ODataFunctions.cs @@ -0,0 +1,406 @@ +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Azure.WebJobs; +using Microsoft.Azure.WebJobs.Extensions.Http; +using Microsoft.Extensions.Logging; +using MsSql.RestApi; +using System; +using System.Threading.Tasks; + +namespace WideWorldImportersFunctions +{ + public static class OData + { + [FunctionName("SalesOrders")] + public static async Task SalesOrders( + [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = null)] HttpRequest req, ILogger log) + { + log.LogInformation("C# HTTP trigger function processed a request."); + try + { + TableSpec salesorders = new TableSpec(schema: "WebApi", table: "SalesOrders", columns: "OrderID,OrderDate,CustomerPurchaseOrderNumber,ExpectedDeliveryDate,PickingCompletedWhen,CustomerID,CustomerName,PhoneNumber,FaxNumber,WebsiteURL,DeliveryLocation,SalesPerson,SalesPersonPhone,SalesPersonEmail"); + return await req.OData(salesorders).GetResult(Environment.GetEnvironmentVariable("SqlDb")); + } + catch (Exception ex) + { + log.LogError($"C# Http trigger function exception: {ex.Message}"); + return new StatusCodeResult(500); + } + } + + [FunctionName("SalesOrderLines")] + public static async Task SalesOrderLines( + [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = null)] HttpRequest req, ILogger log) + { + log.LogInformation("C# HTTP trigger function processed a request."); + try + { + TableSpec salesorderlines = new TableSpec(schema: "WebApi", table: "SalesOrderLines", columns: "OrderLineID,OrderID,Description,Quantity,UnitPrice,TaxRate,ProductName,Brand,Size,ColorName,PackageTypeName,PickingCompletedWhen"); + return await req.OData(salesorderlines).GetResult(Environment.GetEnvironmentVariable("SqlDb")); + } + catch (Exception ex) + { + log.LogError($"C# Http trigger function exception: {ex.Message}"); + return new StatusCodeResult(500); + } + } + + [FunctionName("PurchaseOrders")] + public static async Task PurchaseOrders( + [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = null)] HttpRequest req, ILogger log) + { + log.LogInformation("C# HTTP trigger function processed a request."); + try + { + TableSpec purchaseorders = new TableSpec(schema: "WebApi", table: "PurchaseOrders", columns: "PurchaseOrderID,OrderDate,ExpectedDeliveryDate,SupplierReference,IsOrderFinalized,DeliveryMethodName,ContactName,ContactPhone,ContactFax,ContactEmail,SupplierID"); + return await req.OData(purchaseorders).GetResult(Environment.GetEnvironmentVariable("SqlDb")); + } + catch (Exception ex) + { + log.LogError($"C# Http trigger function exception: {ex.Message}"); + return new StatusCodeResult(500); + } + } + + [FunctionName("PurchaseOrderLines")] + public static async Task PurchaseOrderLines( + [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = null)] HttpRequest req, ILogger log) + { + log.LogInformation("C# HTTP trigger function processed a request."); + try + { + TableSpec purchaseorderlines = new TableSpec(schema: "WebApi", table: "PurchaseOrderLines", columns: "PurchaseOrderLineID,PurchaseOrderID,Description,IsOrderLineFinalized,ProductName,Brand,Size,ColorName,PackageTypeName,OrderedOuters,ReceivedOuters,ExpectedUnitPricePerOuter"); + return await req.OData(purchaseorderlines).GetResult(Environment.GetEnvironmentVariable("SqlDb")); + } + catch (Exception ex) + { + log.LogError($"C# Http trigger function exception: {ex.Message}"); + return new StatusCodeResult(500); + } + } + + [FunctionName("Invoices")] + public static async Task Invoices( + [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = null)] HttpRequest req, ILogger log) + { + log.LogInformation("C# HTTP trigger function processed a request."); + try + { + TableSpec invoices = new TableSpec(schema: "WebApi", table: "Invoices", columns: "InvoiceID,InvoiceDate,CustomerPurchaseOrderNumber,IsCreditNote,TotalDryItems,TotalChillerItems,DeliveryRun,RunPosition,ReturnedDeliveryData,ConfirmedDeliveryTime,ConfirmedReceivedBy,CustomerName,SalesPersonName,ContactName,ContactPhone,ContactEmail,SalesPersonEmail,DeliveryMethodName,CustomerID,OrderID,DeliveryMethodID,ContactPersonID,AccountsPersonID,SalespersonPersonID,PackedByPersonID"); + return await req.OData(invoices).GetResult(Environment.GetEnvironmentVariable("SqlDb")); + } + catch (Exception ex) + { + log.LogError($"C# Http trigger function exception: {ex.Message}"); + return new StatusCodeResult(500); + } + } + + [FunctionName("SpecialDeals")] + public static async Task SpecialDeals( + [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = null)] HttpRequest req, ILogger log) + { + log.LogInformation("C# HTTP trigger function processed a request."); + try + { + TableSpec specialdeals = new TableSpec(schema: "WebApi", table: "SpecialDeals", columns: "SpecialDealID,DealDescription,StartDate,EndDate,DiscountAmount,DiscountPercentage,UnitPrice,StockItemName,Brand,Size,CustomerName,BuyingGroupName,CustomerCategoryName,StockItemID,CustomerID,BuyingGroupID,CustomerCategoryID,StockGroupID"); + return await req.OData(specialdeals).GetResult(Environment.GetEnvironmentVariable("SqlDb")); + } + catch (Exception ex) + { + log.LogError($"C# Http trigger function exception: {ex.Message}"); + return new StatusCodeResult(500); + } + } + + [FunctionName("CustomerTransactions")] + public static async Task CustomerTransactions( + [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = null)] HttpRequest req, ILogger log) + { + log.LogInformation("C# HTTP trigger function processed a request."); + try + { + TableSpec customertransactions = new TableSpec(schema: "WebApi", table: "CustomerTransactions", columns: "CustomerTransactionID,TransactionDate,AmountExcludingTax,TaxAmount,TransactionAmount,OutstandingBalance,FinalizationDate,IsFinalized,CustomerName,TransactionTypeName,InvoiceDate,CustomerPurchaseOrderNumber,PaymentMethodName,CustomerID,TransactionTypeID,InvoiceID,PaymentMethodID"); + return await req.OData(customertransactions).GetResult(Environment.GetEnvironmentVariable("SqlDb")); + } + catch (Exception ex) + { + log.LogError($"C# Http trigger function exception: {ex.Message}"); + return new StatusCodeResult(500); + } + } + + [FunctionName("SupplierTransactions")] + public static async Task SupplierTransactions( + [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = null)] HttpRequest req, ILogger log) + { + log.LogInformation("C# HTTP trigger function processed a request."); + try + { + TableSpec suppliertransactions = new TableSpec(schema: "WebApi", table: "SupplierTransactions", columns: "SupplierTransactionID,TransactionDate,AmountExcludingTax,TaxAmount,TransactionAmount,OutstandingBalance,FinalizationDate,IsFinalized,SupplierName,TransactionTypeName,PaymentMethodName,SupplierID,TransactionTypeID,PurchaseOrderID,PaymentMethodID,OrderDate,IsOrderFinalized,ExpectedDeliveryDate,SupplierReference"); + return await req.OData(suppliertransactions).GetResult(Environment.GetEnvironmentVariable("SqlDb")); + } + catch (Exception ex) + { + log.LogError($"C# Http trigger function exception: {ex.Message}"); + return new StatusCodeResult(500); + } + } + + [FunctionName("Customers")] + public static async Task Customers( + [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = null)] HttpRequest req, ILogger log) + { + log.LogInformation("C# HTTP trigger function processed a request."); + try + { + TableSpec customers = new TableSpec(schema: "WebApi", table: "Customers", columns: "CustomerID,CustomerName,AccountOpenedDate,CustomerCategoryName,PrimaryContact,AlternateContact,PhoneNumber,FaxNumber,WebsiteURL,PostalAddressLine1,PostalAddressLine2,PostalCity,PostalCityID,PostalPostalCode,CreditLimit,IsOnCreditHold,IsStatementSent,PaymentDays,RunPosition,StandardDiscountPercentage,BuyingGroupName,DeliveryLocation,BuyingGroupID,BillToCustomerID,CustomerCategoryID,PrimaryContactPersonID,AlternateContactPersonID"); + return await req.OData(customers).GetResult(Environment.GetEnvironmentVariable("SqlDb")); + } + catch (Exception ex) + { + log.LogError($"C# Http trigger function exception: {ex.Message}"); + return new StatusCodeResult(500); + } + } + + [FunctionName("Suppliers")] + public static async Task Suppliers( + [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = null)] HttpRequest req, ILogger log) + { + log.LogInformation("C# HTTP trigger function processed a request."); + try + { + TableSpec suppliers = new TableSpec(schema: "WebApi", table: "Suppliers", columns: "SupplierID,SupplierName,SupplierCategoryName,PrimaryContact,AlternateContact,PhoneNumber,FaxNumber,WebsiteURL,SupplierReference,DeliveryLocation,BankAccountName,BankAccountBranch,BankAccountCode,BankAccountNumber,BankInternationalCode,PostalAddressLine1,PostalAddressLine2,PostalPostalCode,PaymentDays,SupplierCategoryID"); + return await req.OData(suppliers).GetResult(Environment.GetEnvironmentVariable("SqlDb")); + } + catch (Exception ex) + { + log.LogError($"C# Http trigger function exception: {ex.Message}"); + return new StatusCodeResult(500); + } + } + + [FunctionName("Countries")] + public static async Task Countries( + [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = null)] HttpRequest req, ILogger log) + { + log.LogInformation("C# HTTP trigger function processed a request."); + try + { + TableSpec countries = new TableSpec(schema: "WebApi", table: "Countries", columns: "CountryID,CountryName,FormalName,IsoAlpha3Code,IsoNumericCode,CountryType,LatestRecordedPopulation,Continent,Region,Subregion"); + return await req.OData(countries).GetResult(Environment.GetEnvironmentVariable("SqlDb")); + } + catch (Exception ex) + { + log.LogError($"C# Http trigger function exception: {ex.Message}"); + return new StatusCodeResult(500); + } + } + + [FunctionName("Cities")] + public static async Task Cities( + [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = null)] HttpRequest req, ILogger log) + { + log.LogInformation("C# HTTP trigger function processed a request."); + try + { + TableSpec cities = new TableSpec(schema: "WebApi", table: "Cities", columns: "CityID,CityName,StateProvinceID,LatestRecordedPopulation"); + return await req.OData(cities).GetResult(Environment.GetEnvironmentVariable("SqlDb")); + } + catch (Exception ex) + { + log.LogError($"C# Http trigger function exception: {ex.Message}"); + return new StatusCodeResult(500); + } + } + + [FunctionName("StateProvinces")] + public static async Task StateProvinces( + [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = null)] HttpRequest req, ILogger log) + { + log.LogInformation("C# HTTP trigger function processed a request."); + try + { + TableSpec stateprovinces = new TableSpec(schema: "WebApi", table: "StateProvinces", columns: "StateProvinceID,StateProvinceCode,StateProvinceName,CountryID,SalesTerritory,LatestRecordedPopulation"); + return await req.OData(stateprovinces).GetResult(Environment.GetEnvironmentVariable("SqlDb")); + } + catch (Exception ex) + { + log.LogError($"C# Http trigger function exception: {ex.Message}"); + return new StatusCodeResult(500); + } + } + + [FunctionName("StockItems")] + public static async Task StockItems( + [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = null)] HttpRequest req, ILogger log) + { + log.LogInformation("C# HTTP trigger function processed a request."); + try + { + TableSpec stockitems = new TableSpec(schema: "WebApi", table: "StockItems", columns: "StockItemID,StockItemName,SupplierName,SupplierReference,ColorName,OuterPackage,UnitPackage,Brand,Size,LeadTimeDays,QuantityPerOuter,IsChillerStock,Barcode,TaxRate,UnitPrice,RecommendedRetailPrice,TypicalWeightPerUnit,MarketingComments,InternalComments,CustomFields,QuantityOnHand,BinLocation,LastStocktakeQuantity,LastCostPrice,ReorderLevel,TargetStockLevel,SupplierID,ColorID,UnitPackageID,OuterPackageID"); + return await req.OData(stockitems).GetResult(Environment.GetEnvironmentVariable("SqlDb")); + } + catch (Exception ex) + { + log.LogError($"C# Http trigger function exception: {ex.Message}"); + return new StatusCodeResult(500); + } + } + + [FunctionName("PackageTypes")] + public static async Task PackageTypes( + [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = null)] HttpRequest req, ILogger log) + { + log.LogInformation("C# HTTP trigger function processed a request."); + try + { + TableSpec packagetypes = new TableSpec(schema: "WebApi", table: "PackageTypes", columns: "PackageTypeID,PackageTypeName"); + return await req.OData(packagetypes).GetResult(Environment.GetEnvironmentVariable("SqlDb")); + } + catch (Exception ex) + { + log.LogError($"C# Http trigger function exception: {ex.Message}"); + return new StatusCodeResult(500); + } + } + + [FunctionName("Colors")] + public static async Task Colors( + [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = null)] HttpRequest req, ILogger log) + { + log.LogInformation("C# HTTP trigger function processed a request."); + try + { + TableSpec colors = new TableSpec(schema: "WebApi", table: "Colors", columns: "ColorID,ColorName"); + return await req.OData(colors).GetResult(Environment.GetEnvironmentVariable("SqlDb")); + } + catch (Exception ex) + { + log.LogError($"C# Http trigger function exception: {ex.Message}"); + return new StatusCodeResult(500); + } + } + + [FunctionName("StockGroups")] + public static async Task StockGroups( + [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = null)] HttpRequest req, ILogger log) + { + log.LogInformation("C# HTTP trigger function processed a request."); + try + { + TableSpec stockgroups = new TableSpec(schema: "WebApi", table: "StockGroups", columns: "StockGroupID,StockGroupName"); + return await req.OData(stockgroups).GetResult(Environment.GetEnvironmentVariable("SqlDb")); + } + catch (Exception ex) + { + log.LogError($"C# Http trigger function exception: {ex.Message}"); + return new StatusCodeResult(500); + } + } + + [FunctionName("BuyingGroups")] + public static async Task BuyingGroups( + [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = null)] HttpRequest req, ILogger log) + { + log.LogInformation("C# HTTP trigger function processed a request."); + try + { + TableSpec buyinggroups = new TableSpec(schema: "WebApi", table: "BuyingGroups", columns: "BuyingGroupID,BuyingGroupName"); + return await req.OData(buyinggroups).GetResult(Environment.GetEnvironmentVariable("SqlDb")); + } + catch (Exception ex) + { + log.LogError($"C# Http trigger function exception: {ex.Message}"); + return new StatusCodeResult(500); + } + } + + [FunctionName("CustomerCategories")] + public static async Task CustomerCategories( + [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = null)] HttpRequest req, ILogger log) + { + log.LogInformation("C# HTTP trigger function processed a request."); + try + { + TableSpec customercategories = new TableSpec(schema: "WebApi", table: "CustomerCategories", columns: "CustomerCategoryID,CustomerCategoryName"); + return await req.OData(customercategories).GetResult(Environment.GetEnvironmentVariable("SqlDb")); + } + catch (Exception ex) + { + log.LogError($"C# Http trigger function exception: {ex.Message}"); + return new StatusCodeResult(500); + } + } + + [FunctionName("SupplierCategories")] + public static async Task SupplierCategories( + [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = null)] HttpRequest req, ILogger log) + { + log.LogInformation("C# HTTP trigger function processed a request."); + try + { + TableSpec suppliercategories = new TableSpec(schema: "WebApi", table: "SupplierCategories", columns: "SupplierCategoryID,SupplierCategoryName"); + return await req.OData(suppliercategories).GetResult(Environment.GetEnvironmentVariable("SqlDb")); + } + catch (Exception ex) + { + log.LogError($"C# Http trigger function exception: {ex.Message}"); + return new StatusCodeResult(500); + } + } + + [FunctionName("TransactionTypes")] + public static async Task TransactionTypes( + [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = null)] HttpRequest req, ILogger log) + { + log.LogInformation("C# HTTP trigger function processed a request."); + try + { + TableSpec transactiontypes = new TableSpec(schema: "WebApi", table: "TransactionTypes", columns: "TransactionTypeID,TransactionTypeName"); + return await req.OData(transactiontypes).GetResult(Environment.GetEnvironmentVariable("SqlDb")); + } + catch (Exception ex) + { + log.LogError($"C# Http trigger function exception: {ex.Message}"); + return new StatusCodeResult(500); + } + } + + [FunctionName("PaymentMethods")] + public static async Task PaymentMethods( + [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = null)] HttpRequest req, ILogger log) + { + log.LogInformation("C# HTTP trigger function processed a request."); + try + { + TableSpec paymentmethods = new TableSpec(schema: "WebApi", table: "PaymentMethods", columns: "PaymentMethodID,PaymentMethodName"); + return await req.OData(paymentmethods).GetResult(Environment.GetEnvironmentVariable("SqlDb")); + } + catch (Exception ex) + { + log.LogError($"C# Http trigger function exception: {ex.Message}"); + return new StatusCodeResult(500); + } + } + + [FunctionName("DeliveryMethods")] + public static async Task DeliveryMethods( + [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = null)] HttpRequest req, ILogger log) + { + log.LogInformation("C# HTTP trigger function processed a request."); + try + { + TableSpec deliverymethods = new TableSpec(schema: "WebApi", table: "DeliveryMethods", columns: "DeliveryMethodID,DeliveryMethodName"); + return await req.OData(deliverymethods).GetResult(Environment.GetEnvironmentVariable("SqlDb")); + } + catch (Exception ex) + { + log.LogError($"C# Http trigger function exception: {ex.Message}"); + return new StatusCodeResult(500); + } + } + + } +} diff --git a/samples/databases/wide-world-importers/wwi-azure-functions/ODataFunctions.tt b/samples/databases/wide-world-importers/wwi-azure-functions/ODataFunctions.tt new file mode 100644 index 00000000..2615c034 --- /dev/null +++ b/samples/databases/wide-world-importers/wwi-azure-functions/ODataFunctions.tt @@ -0,0 +1,51 @@ +<#@ output extension=".cs"#> +<#@ assembly name="Newtonsoft.Json" #> +<#@ template language="C#" hostspecific="True" #> +<# + var o = Newtonsoft.Json.Linq.JObject.Parse(System.IO.File.ReadAllText(this.Host.ResolvePath(".") + "\\local.settings.json")); + var json = o["ApiModel"].ToString(); + TableDef[] config = Newtonsoft.Json.JsonConvert.DeserializeObject(json); +#> +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Azure.WebJobs; +using Microsoft.Azure.WebJobs.Extensions.Http; +using Microsoft.Extensions.Logging; +using MsSql.RestApi; +using System; +using System.Threading.Tasks; + +namespace WideWorldImportersFunctions +{ + public static class OData + { +<# foreach(var t in config) {#> +<# if(string.IsNullOrEmpty(t.ODataColumns)) continue; #> + [FunctionName("<#= t.Table #>")] + public static async Task <#= t.Table #>( + [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = null)] HttpRequest req, ILogger log) + { + log.LogInformation("C# HTTP trigger function processed a request."); + try + { + TableSpec <#= t.Table.ToLower() #> = new TableSpec(schema: "<#= t.Schema #>", table: "<#= t.Table #>", columns: "<#= t.ODataColumns #>"); + return await req.OData(<#= t.Table.ToLower() #>).GetResult(Environment.GetEnvironmentVariable("SqlDb")); + } + catch (Exception ex) + { + log.LogError($"C# Http trigger function exception: {ex.Message}"); + return new StatusCodeResult(500); + } + } + +<# } #> + } +} +<#+ + public class TableDef { + public string Schema {get; set;} + public string Table {get; set;} + public string ODataColumns {get; set;} + public bool IsReadOnly {get; set;} + } +#> \ No newline at end of file diff --git a/samples/databases/wide-world-importers/wwi-azure-functions/SalesOrders.cs b/samples/databases/wide-world-importers/wwi-azure-functions/SalesOrders.cs deleted file mode 100644 index 03b00c4a..00000000 --- a/samples/databases/wide-world-importers/wwi-azure-functions/SalesOrders.cs +++ /dev/null @@ -1,32 +0,0 @@ -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Mvc; -using Microsoft.Azure.WebJobs; -using Microsoft.Azure.WebJobs.Extensions.Http; -using Microsoft.Extensions.Logging; -using MsSql.RestApi; -using System; -using System.Threading.Tasks; - -namespace wwi_azure_functions -{ - public static class SalesOrders - { - [FunctionName("SalesOrders")] - public static async Task Run( - [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req, ILogger log) - { - log.LogInformation("C# HTTP trigger function processed a request."); - - try - { - TableSpec tableSpec = new TableSpec(schema: "WebApi", name: "SalesOrders", columnList: "OrderID,OrderDate,CustomerPurchaseOrderNumber,ExpectedDeliveryDate,PickingCompletedWhen,CustomerID,CustomerName,PhoneNumber,FaxNumber,WebsiteURL,DeliveryLocation,SalesPerson,SalesPersonPhone,SalesPersonEmail"); - return await req.OData(tableSpec).GetResult(Environment.GetEnvironmentVariable("SqlDb")); - } - catch (Exception ex) - { - log.LogError($"C# Http trigger function exception: {ex.Message}"); - return new StatusCodeResult(500); - } - } - } -} diff --git a/samples/databases/wide-world-importers/wwi-azure-functions/StockItems.cs b/samples/databases/wide-world-importers/wwi-azure-functions/StockItems.cs deleted file mode 100644 index 340e7fa9..00000000 --- a/samples/databases/wide-world-importers/wwi-azure-functions/StockItems.cs +++ /dev/null @@ -1,32 +0,0 @@ -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Mvc; -using Microsoft.Azure.WebJobs; -using Microsoft.Azure.WebJobs.Extensions.Http; -using Microsoft.Extensions.Logging; -using MsSql.RestApi; -using System; -using System.Threading.Tasks; - -namespace wwi_azure_functions -{ - public static class StockItems - { - [FunctionName("StockItems")] - public static async Task Run( - [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = null)] HttpRequest req, ILogger log) - { - log.LogInformation("C# HTTP trigger function processed a request."); - - try - { - TableSpec stockitems = new TableSpec("WebApi", "StockItems", "StockItemID,StockItemName,SupplierName,SupplierReference,ColorName,OuterPackage,UnitPackage,Brand,Size,LeadTimeDays,QuantityPerOuter,IsChillerStock,Barcode,TaxRate,UnitPrice,RecommendedRetailPrice,TypicalWeightPerUnit,MarketingComments,InternalComments,CustomFields,QuantityOnHand,BinLocation,LastStocktakeQuantity,LastCostPrice,ReorderLevel,TargetStockLevel,SupplierID,ColorID,UnitPackageID,OuterPackageID"); - return await req.OData(stockitems).GetResult(Environment.GetEnvironmentVariable("SqlDb")); - } - catch (Exception ex) - { - log.LogError($"C# Http trigger function exception: {ex.Message}"); - return new StatusCodeResult(500); - } - } - } -} diff --git a/samples/databases/wide-world-importers/wwi-azure-functions/Suppliers.cs b/samples/databases/wide-world-importers/wwi-azure-functions/Suppliers.cs deleted file mode 100644 index 7b1e3463..00000000 --- a/samples/databases/wide-world-importers/wwi-azure-functions/Suppliers.cs +++ /dev/null @@ -1,32 +0,0 @@ -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Mvc; -using Microsoft.Azure.WebJobs; -using Microsoft.Azure.WebJobs.Extensions.Http; -using Microsoft.Extensions.Logging; -using MsSql.RestApi; -using System; -using System.Threading.Tasks; - -namespace wwi_azure_functions -{ - public static class Suppliers - { - [FunctionName("Suppliers")] - public static async Task Run( - [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = null)] HttpRequest req, ILogger log) - { - log.LogInformation("C# HTTP trigger function processed a request."); - - try - { - TableSpec suppliers = new TableSpec("WebApi", "Suppliers", "SupplierID,SupplierName,SupplierCategoryName,PrimaryContact,AlternateContact,PhoneNumber,FaxNumber,WebsiteURL,SupplierReference,DeliveryLocation,BankAccountName,BankAccountBranch,BankAccountCode,BankAccountNumber,BankInternationalCode,PostalAddressLine1,PostalAddressLine2,PostalPostalCode,PaymentDays,SupplierCategoryID"); - return await req.OData(suppliers).GetResult(Environment.GetEnvironmentVariable("SqlDb")); - } - catch (Exception ex) - { - log.LogError($"C# Http trigger function exception: {ex.Message}"); - return new StatusCodeResult(500); - } - } - } -} diff --git a/samples/databases/wide-world-importers/wwi-azure-functions/wwi-azure-functions.csproj b/samples/databases/wide-world-importers/wwi-azure-functions/wwi-azure-functions.csproj index 4b50fc64..c5a3f4b7 100644 --- a/samples/databases/wide-world-importers/wwi-azure-functions/wwi-azure-functions.csproj +++ b/samples/databases/wide-world-importers/wwi-azure-functions/wwi-azure-functions.csproj @@ -1,4 +1,4 @@ - + netstandard2.0 v2 @@ -6,7 +6,7 @@ - + @@ -16,5 +16,19 @@ PreserveNewest Never + + TextTemplatingFileGenerator + ODataFunctions.cs + + + + + + + + True + True + ODataFunctions.tt + \ No newline at end of file