Test WPF Desktop App with Caliburn And RestSharp

This commit is contained in:
2019-02-26 01:26:03 +01:00
parent 35bd2890ed
commit e8fd116eab
38 changed files with 996 additions and 30 deletions

View File

@@ -0,0 +1,47 @@
using System;
using System.Collections.Generic;
using System.Windows;
using LaDOSE.DTO;
using RestSharp;
using RestSharp.Authenticators;
using RestSharp.Serialization.Json;
namespace LaDOSE.DesktopApp.Services
{
public class RestService
{
public RestClient Client { get; set; }
public RestService()
{
Client = new RestClient("http://localhost:5000/");
var restRequest = new RestRequest("users/auth", Method.POST);
restRequest.AddJsonBody(new { username = "****", password = "*****" });
var response = Client.Post(restRequest);
if (response.IsSuccessful)
{
JsonDeserializer d = new JsonDeserializer();
var applicationUser = d.Deserialize<ApplicationUser>(response);
Client.Authenticator = new JwtAuthenticator($"{applicationUser.Token}");
}
else
{
throw new Exception("No Service Avaliable");
}
}
public List<WPEvent> GetEvents()
{
var restRequest = new RestRequest("/api/wordpress/WPEvent", Method.GET);
var restResponse = Client.Get<List<WPEvent>>(restRequest);
return restResponse.Data;
}
public List<Game> GetGames()
{
var restRequest = new RestRequest("/api/Game", Method.GET);
var restResponse = Client.Get<List<Game>>(restRequest);
return restResponse.Data;
}
}
}