Skip to content
This repository has been archived by the owner on Apr 23, 2023. It is now read-only.

Commit

Permalink
add missing code
Browse files Browse the repository at this point in the history
  • Loading branch information
christiannagel committed Mar 6, 2018
1 parent 8298d0a commit 92da07a
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions API/Sync/BooksServiceSample/BookFunctionApp/BookFunction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System;
using Microsoft.Extensions.DependencyInjection;
using BooksServiceSample.Services;
using BooksServiceSample.Models;

namespace BookFunctionApp
{
Expand All @@ -18,6 +19,7 @@ static BookFunction()
{
ConfigureServices();
FeedSampleChapters();
GetRequiredServices();
}

private static void FeedSampleChapters()
Expand All @@ -34,6 +36,15 @@ private static void ConfigureServices()
ApplicationServices = services.BuildServiceProvider();
}

private static void GetRequiredServices()
{
s_bookChaptersService =
ApplicationServices.GetRequiredService<IBookChaptersService>();
}

private static IBookChaptersService s_bookChaptersService;


public static IServiceProvider ApplicationServices { get; private set; }

[FunctionName("BookFunction")]
Expand All @@ -48,8 +59,10 @@ public static IActionResult Run([HttpTrigger(AuthorizationLevel.Anonymous, "get"
result = DoGet(req);
break;
case "POST":
result = DoPost(req);
break;
case "PUT":
result = DoPut(req);
break;
default:
break;
Expand All @@ -73,5 +86,23 @@ private static IActionResult DoGet(HttpRequest req)
var chapters = bookChapterService.GetAll();
return new OkObjectResult(chapters);
}

private static IActionResult DoPost(HttpRequest req)
{
string json = new StreamReader(req.Body).ReadToEnd();
BookChapter chapter = JsonConvert.DeserializeObject<BookChapter>(json);
s_bookChaptersService.Add(chapter);
return new OkResult();
}


private static IActionResult DoPut(HttpRequest req)
{
string json = new StreamReader(req.Body).ReadToEnd();
BookChapter chapter = JsonConvert.DeserializeObject<BookChapter>(json);
s_bookChaptersService.Update(chapter);
return new OkResult();
}

}
}

0 comments on commit 92da07a

Please sign in to comment.