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

Commit 92da07a

Browse files
add missing code
1 parent 8298d0a commit 92da07a

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

API/Sync/BooksServiceSample/BookFunctionApp/BookFunction.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using System;
1010
using Microsoft.Extensions.DependencyInjection;
1111
using BooksServiceSample.Services;
12+
using BooksServiceSample.Models;
1213

1314
namespace BookFunctionApp
1415
{
@@ -18,6 +19,7 @@ static BookFunction()
1819
{
1920
ConfigureServices();
2021
FeedSampleChapters();
22+
GetRequiredServices();
2123
}
2224

2325
private static void FeedSampleChapters()
@@ -34,6 +36,15 @@ private static void ConfigureServices()
3436
ApplicationServices = services.BuildServiceProvider();
3537
}
3638

39+
private static void GetRequiredServices()
40+
{
41+
s_bookChaptersService =
42+
ApplicationServices.GetRequiredService<IBookChaptersService>();
43+
}
44+
45+
private static IBookChaptersService s_bookChaptersService;
46+
47+
3748
public static IServiceProvider ApplicationServices { get; private set; }
3849

3950
[FunctionName("BookFunction")]
@@ -48,8 +59,10 @@ public static IActionResult Run([HttpTrigger(AuthorizationLevel.Anonymous, "get"
4859
result = DoGet(req);
4960
break;
5061
case "POST":
62+
result = DoPost(req);
5163
break;
5264
case "PUT":
65+
result = DoPut(req);
5366
break;
5467
default:
5568
break;
@@ -73,5 +86,23 @@ private static IActionResult DoGet(HttpRequest req)
7386
var chapters = bookChapterService.GetAll();
7487
return new OkObjectResult(chapters);
7588
}
89+
90+
private static IActionResult DoPost(HttpRequest req)
91+
{
92+
string json = new StreamReader(req.Body).ReadToEnd();
93+
BookChapter chapter = JsonConvert.DeserializeObject<BookChapter>(json);
94+
s_bookChaptersService.Add(chapter);
95+
return new OkResult();
96+
}
97+
98+
99+
private static IActionResult DoPut(HttpRequest req)
100+
{
101+
string json = new StreamReader(req.Body).ReadToEnd();
102+
BookChapter chapter = JsonConvert.DeserializeObject<BookChapter>(json);
103+
s_bookChaptersService.Update(chapter);
104+
return new OkResult();
105+
}
106+
76107
}
77108
}

0 commit comments

Comments
 (0)