Beispiel #1
0
        /// <summary>
        /// Runs the Queue Trigger function.
        /// </summary>
        /// <param name="myQueueItem">Queue message.</param>
        /// <param name="log"><see cref="TraceWriter"/> instance.</param>
        public static async void Run(string myQueueItem, TraceWriter log)
        {
            log.Info($"C# Queue trigger function processed: {myQueueItem}");

            var model = JsonConvert.DeserializeObject <ProductModel>(myQueueItem);

            var connectionString = ConfigurationManager.ConnectionStrings["PrecompiledDbContext"].ConnectionString;
            var dbContext        = new PrecompiledDbContext(connectionString);

            var service = new ProductService(dbContext);

            var result = await service.SaveAsync(model).ConfigureAwait(false);

            log.Info("Queue has been processed");
        }
Beispiel #2
0
        /// <summary>
        /// Runs the HTTP trigger function.
        /// </summary>
        /// <param name="req"><see cref="HttpRequestMessage"/> instance.</param>
        /// <param name="log"><see cref="TraceWriter"/> instance.</param>
        /// <returns>Returns the <see cref="HttpResponseMessage"/> instance.</returns>
        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));
        }