using System; | |
using System.Configuration; | |
using System.Linq; | |
using System.Net; | |
using System.Net.Http; | |
using System.Threading.Tasks; | |
using Microsoft.Azure.WebJobs.Host; | |
using PrecompiledSample.EntityModels; | |
using PrecompiledSample.Services; | |
namespace PrecompiledSample.Functions | |
{ | |
public static class GetProductHttpTrigger | |
{ | |
public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log) | |
{ | |
log.Info("C# HTTP trigger function processed a request."); | |
var productId = req.GetQueryNameValuePairs() | |
.FirstOrDefault(q => q.Key.Equals("id", StringComparison.CurrentCultureIgnoreCase)) | |
.Value; | |
var connectionString = ConfigurationManager.ConnectionStrings["PrecompiledDbContext"].ConnectionString; | |
var dbContext = new PrecompiledDbContext(connectionString); | |
var service = new ProductService(dbContext); | |
var product = await service.GetAsync(productId).ConfigureAwait(false); | |
return req.CreateResponse(HttpStatusCode.OK, product); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment