forked from dmelgarejoPDESGO/serverless-openhack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
UserService.cs
37 lines (32 loc) · 1.16 KB
/
UserService.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
using System;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
using BFYOC.Models;
using Newtonsoft.Json;
namespace BFYOC
{
public class UserService
{
private static User[] users = new User[]
{
new User{
UserId = new Guid("cc20a6fb-a91f-4192-874d-132493685376"),
UserName = "doreen.riddle",
FullName = "Doreen Riddle",
}
};
static readonly HttpClient client = new HttpClient();
private static readonly string GetUserUrl = "https://serverlessohuser.trafficmanager.net/api/GetUser";
public async Task<User> GetUserAsync(Guid userId)
{
var response = await client.GetAsync($"{GetUserUrl}?userId={userId}");
if(response.StatusCode == System.Net.HttpStatusCode.BadRequest
|| response.StatusCode == System.Net.HttpStatusCode.NotFound)
return null;
var responseBody = await response.Content.ReadAsStringAsync();
var user = JsonConvert.DeserializeObject<User>(responseBody);
return user;
}
}
}