diff --git a/.vs/MyCore/v15/Server/sqlite3/storage.ide b/.vs/MyCore/v15/Server/sqlite3/storage.ide
index ace4fd9..816b59b 100644
Binary files a/.vs/MyCore/v15/Server/sqlite3/storage.ide and b/.vs/MyCore/v15/Server/sqlite3/storage.ide differ
diff --git a/.vs/MyCore/v15/Server/sqlite3/storage.ide-shm b/.vs/MyCore/v15/Server/sqlite3/storage.ide-shm
index 8131853..b28f1bd 100644
Binary files a/.vs/MyCore/v15/Server/sqlite3/storage.ide-shm and b/.vs/MyCore/v15/Server/sqlite3/storage.ide-shm differ
diff --git a/.vs/MyCore/v15/Server/sqlite3/storage.ide-wal b/.vs/MyCore/v15/Server/sqlite3/storage.ide-wal
index f80eca8..ac50bd8 100644
Binary files a/.vs/MyCore/v15/Server/sqlite3/storage.ide-wal and b/.vs/MyCore/v15/Server/sqlite3/storage.ide-wal differ
diff --git a/MyCore/Controllers/OddController.cs b/MyCore/Controllers/OddController.cs
new file mode 100644
index 0000000..bcd0321
--- /dev/null
+++ b/MyCore/Controllers/OddController.cs
@@ -0,0 +1,142 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+using Microsoft.AspNetCore.Authorization;
+using Microsoft.AspNetCore.Mvc;
+using MQTTnet;
+using MQTTnet.Client;
+using MQTTnet.Server;
+using MyCore.DTO;
+using MyCore.Models;
+using MyCore.Services;
+using static MyCore.Services.OddService;
+
+namespace MyCore.Controllers
+{
+ [Authorize(Roles = "Admin")]
+ [Route("api/odd")]
+ [ApiController]
+ public class OddController : ControllerBase
+ {
+ private OddService oddService = new OddService(OddService.RegionOdd.UK);
+
+ ///
+ /// Get odds for one country and one odd value maximum
+ ///
+ /// id of country, e.g = BE for Belgium
+ /// Odd Maximum value
+ [AllowAnonymous]
+ [ProducesResponseType(typeof(List), 200)]
+ [ProducesResponseType(typeof(string), 404)]
+ [ProducesResponseType(typeof(string), 500)]
+ [HttpGet("country/{id}/{oddRequest}")]
+ public async Task>> GetForCountry(string id, double oddRequest)
+ {
+ try
+ {
+ try
+ {
+ League leagueTest = new League(id);
+ }
+ catch (Exception ex)
+ {
+ return new ObjectResult("The league you mentionned not exists") { StatusCode = 404 };
+ }
+
+ var result = await GetOddsForCountry(id, oddRequest);
+
+ return new OkObjectResult(result);
+ }
+ catch (Exception e)
+ {
+ Console.WriteLine(e);
+
+ return new ObjectResult("The league you mentionned not exists") { StatusCode = 500 };
+ }
+ }
+
+ ///
+ /// Get odds for one country and one odd value maximum
+ ///
+ /// id of country, e.g = BE for Belgium
+ /// Odd Maximum value
+ [AllowAnonymous]
+ [ProducesResponseType(typeof(List), 200)]
+ [ProducesResponseType(typeof(string), 404)]
+ [ProducesResponseType(typeof(string), 500)]
+ [HttpGet("{oddRequest}")]
+ public async Task>> GetAll(double oddRequest)
+ {
+ try
+ {
+ List oddToSend = new List();
+ foreach (var league in oddService.allLeagues)
+ {
+ var result = await GetOddsForCountry(league.Identifiant, oddRequest);
+
+ foreach (var element in result)
+ {
+ oddToSend.Add(element);
+ }
+ }
+
+ return new OkObjectResult(oddToSend);
+ }
+ catch (Exception e)
+ {
+ Console.WriteLine(e);
+
+ return new ObjectResult("The league you mentionned not exists") { StatusCode = 500 };
+ }
+ }
+
+ public async Task> GetOddsForCountry(string id, double oddRequest)
+ {
+ League league = new League(id);
+ var result = await oddService.GetOddsForLeague(league);
+
+ List oddToKeep = new List();
+
+ foreach (var odd in result)
+ {
+ if (odd.Sites.Where(s => s.Site_key == "unibet" && s.Odds.H2h.Where(o => o <= oddRequest).Count() > 0).Count() > 0)
+ {
+ var unibet = odd.Sites.Where(s => s.Site_key == "unibet").ToList().FirstOrDefault();
+
+ OddNice oddNice = new OddNice();
+ oddNice.Commence_time = odd.Commence_time;
+ oddNice.Home_team = odd.Home_team;
+ oddNice.Teams = odd.Teams;
+ oddNice.Odds = new OddH2H();
+ oddNice.Odds.HomeOdd = unibet.Odds.H2h.ToArray()[0];
+ oddNice.Odds.VisitOdd = unibet.Odds.H2h.ToArray()[1];
+ oddNice.Odds.DrawOdd = unibet.Odds.H2h.ToArray()[2];
+ oddToKeep.Add(oddNice);
+ }
+ }
+ return oddToKeep;
+ }
+
+ // POST api/values
+ [HttpPost]
+ public void Post([FromBody] string value)
+ {
+ // For more information on protecting this API from Cross Site Request Forgery (CSRF) attacks, see https://go.microsoft.com/fwlink/?LinkID=717803
+ }
+
+ // PUT api/values/5
+ [HttpPut("{id}")]
+ public void Put(int id, [FromBody] string value)
+ {
+ // For more information on protecting this API from Cross Site Request Forgery (CSRF) attacks, see https://go.microsoft.com/fwlink/?LinkID=717803
+ }
+
+ // DELETE api/values/5
+ [HttpDelete("{id}")]
+ public void Delete(int id)
+ {
+ // For more information on protecting this API from Cross Site Request Forgery (CSRF) attacks, see https://go.microsoft.com/fwlink/?LinkID=717803
+ }
+ }
+}
diff --git a/MyCore/Controllers/ValuesController.cs b/MyCore/Controllers/ValuesController.cs
index 81a094f..c1295c2 100644
--- a/MyCore/Controllers/ValuesController.cs
+++ b/MyCore/Controllers/ValuesController.cs
@@ -18,8 +18,6 @@ namespace MyCore.Controllers
[ApiController]
public class ValuesController : ControllerBase
{
- private OddService oddService = new OddService(OddService.RegionOdd.UK);
-
// GET api/values
///
@@ -32,28 +30,6 @@ namespace MyCore.Controllers
{
WidgetWeather widgetWeather = new WidgetWeather();
- try
- {
- League league = new League("BE");
- oddService.GetOddsForLeague(league).ContinueWith(res =>
- {
- if (res.Status == TaskStatus.RanToCompletion)
- {
- var test = res.Result;
- }
- else
- {
-
- }
- }); ;
- }
- catch (Exception e)
- {
- Console.WriteLine(e);
- }
-
-
-
return new string[] { "value1", "value2" };
}
diff --git a/MyCore/DTO/Odd.cs b/MyCore/DTO/Odd.cs
index 5eed4f0..29603a5 100644
--- a/MyCore/DTO/Odd.cs
+++ b/MyCore/DTO/Odd.cs
@@ -20,13 +20,26 @@ namespace MyCore.DTO
public string Site_key;
public string Site_nice;
public int Last_update;
- public OddMatch OddMatch;
+ public OddMatch Odds;
}
public class OddMatch
+ {
+ public IEnumerable H2h;
+ }
+
+ public class OddH2H
{
public double HomeOdd;
public double DrawOdd;
public double VisitOdd;
}
+
+ public class OddNice
+ {
+ public List Teams;
+ public int Commence_time;
+ public string Home_team;
+ public OddH2H Odds;
+ }
}
diff --git a/MyCore/DTO/RequestParam.cs b/MyCore/DTO/RequestParam.cs
new file mode 100644
index 0000000..19b6817
--- /dev/null
+++ b/MyCore/DTO/RequestParam.cs
@@ -0,0 +1,21 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+
+namespace MyCore.DTO
+{
+ public class RequestParam
+ {
+ private const int maxPageCount = 50;
+ public int? Page { get; set; }
+ private int? _pageCount = maxPageCount;
+ public int? PageCount
+ {
+ get { return _pageCount; }
+ set { _pageCount = (value > maxPageCount) ? maxPageCount : value; }
+ }
+ public string SiteId { get; set; }
+ public string OrderBy { get; set; } = "Name";
+ }
+}
diff --git a/MyCore/Services/OddService.cs b/MyCore/Services/OddService.cs
index abbd015..a6c76ff 100644
--- a/MyCore/Services/OddService.cs
+++ b/MyCore/Services/OddService.cs
@@ -1,8 +1,11 @@
using MyCore.DTO;
+using Newtonsoft.Json;
+using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
+using System.Text;
using System.Threading.Tasks;
using System.Web;
@@ -21,8 +24,10 @@ namespace MyCore.Services
public class League
{
public string ApiIdentifiant { get; set; }
+ public string Identifiant { get; set; }
public League(string league) {
+ Identifiant = league;
switch (league)
{
case "BE":
@@ -84,27 +89,67 @@ namespace MyCore.Services
_url = $"{_servicePoint}apiKey={_apiKey}®ion={_region}";
_client.BaseAddress = new Uri(_url);
+
+ // TO REVIEW !
+ League leagueBE = new League("BE");
+ League leagueUK = new League("UK");
+ League leagueDK = new League("DK");
+ League leagueFR = new League("FR");
+ League leagueDE = new League("DE");
+ League leagueIT = new League("IT");
+ League leagueNE = new League("NE");
+ League leaguePT = new League("PT");
+ League leagueRU = new League("RU");
+ League leagueES = new League("ES");
+ League leagueCH = new League("CH");
+ League leagueTR = new League("TR");
+
+ allLeagues.Add(leagueBE);
+ allLeagues.Add(leagueUK);
+ allLeagues.Add(leagueDK);
+ allLeagues.Add(leagueFR);
+ allLeagues.Add(leagueDE);
+ allLeagues.Add(leagueIT);
+ allLeagues.Add(leagueNE);
+ allLeagues.Add(leaguePT);
+ allLeagues.Add(leagueRU);
+ allLeagues.Add(leagueES);
+ allLeagues.Add(leagueCH);
+ allLeagues.Add(leagueTR);
}
public async Task> GetOddsForLeague(League league)
{
- List oddsToReturn = new List();
+ try
+ {
+
+ using (HttpClient client = new HttpClient())
+ {
+ var builder = new UriBuilder(_servicePoint);
+ builder.Port = -1;
+ var query = HttpUtility.ParseQueryString(builder.Query);
+ query["apiKey"] = _apiKey;
+ query["region"] = _region;
+ query["sport"] = league.ApiIdentifiant;
+ builder.Query = query.ToString();
+ string url = builder.ToString();
- var builder = new UriBuilder(_servicePoint);
- builder.Port = -1;
- var query = HttpUtility.ParseQueryString(builder.Query);
- query["apiKey"] = _apiKey;
- query["region"] = _region;
- query["sport"] = league.ApiIdentifiant;
- builder.Query = query.ToString();
- string url = builder.ToString();
+ _client.BaseAddress = new Uri(url);
- _client.BaseAddress = new Uri(url);
- var result = await _client.GetAsync(url);
-
- Console.WriteLine(result.StatusCode);
-
- return oddsToReturn;
+ var response = await client.GetAsync(url);
+ if (response != null)
+ {
+ var jsonString = await response.Content.ReadAsStringAsync();
+ var data = ((JObject)JsonConvert.DeserializeObject(jsonString))["data"];
+ return JsonConvert.DeserializeObject>(data.ToString());
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ Console.WriteLine(ex);
+ }
+ return null;
}
public List GetOddsForAllLeagues()
diff --git a/MyCore/bin/Debug/netcoreapp2.1/MyCore.xml b/MyCore/bin/Debug/netcoreapp2.1/MyCore.xml
index f6d0924..1229835 100644
--- a/MyCore/bin/Debug/netcoreapp2.1/MyCore.xml
+++ b/MyCore/bin/Debug/netcoreapp2.1/MyCore.xml
@@ -56,6 +56,20 @@
It's a mqtt publish test ! :)
+
+
+ Get odds for one country and one odd value maximum
+
+ id of country, e.g = BE for Belgium
+ Odd Maximum value
+
+
+
+ Get odds for one country and one odd value maximum
+
+ id of country, e.g = BE for Belgium
+ Odd Maximum value
+
Get a list of user
diff --git a/MyCore/obj/Debug/netcoreapp2.1/MyCore.xml b/MyCore/obj/Debug/netcoreapp2.1/MyCore.xml
index f6d0924..1229835 100644
--- a/MyCore/obj/Debug/netcoreapp2.1/MyCore.xml
+++ b/MyCore/obj/Debug/netcoreapp2.1/MyCore.xml
@@ -56,6 +56,20 @@
It's a mqtt publish test ! :)
+
+
+ Get odds for one country and one odd value maximum
+
+ id of country, e.g = BE for Belgium
+ Odd Maximum value
+
+
+
+ Get odds for one country and one odd value maximum
+
+ id of country, e.g = BE for Belgium
+ Odd Maximum value
+
Get a list of user