init
This commit is contained in:
commit
e124a47765
19374 changed files with 9806149 additions and 0 deletions
118
Kreta.Client/LEP/LepClient.cs
Normal file
118
Kreta.Client/LEP/LepClient.cs
Normal file
|
@ -0,0 +1,118 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using Newtonsoft.Json;
|
||||
using RestSharp;
|
||||
|
||||
namespace Kreta.Client.LEP
|
||||
{
|
||||
public class LepClient
|
||||
{
|
||||
private readonly string baseUrl;
|
||||
private readonly string apiKey;
|
||||
|
||||
public LepClient(string baseUrl, string apiKey)
|
||||
{
|
||||
this.baseUrl = baseUrl;
|
||||
this.apiKey = apiKey;
|
||||
}
|
||||
|
||||
private IRestResponse Http(Method method, string relativeUri, Dictionary<string, string> parameters = null, Object body = null)
|
||||
{
|
||||
var restRequest = new RestRequest(relativeUri, method);
|
||||
restRequest.AddHeader("ApiKey", apiKey);
|
||||
|
||||
if (parameters != null && parameters.Count > 0)
|
||||
{
|
||||
foreach (var parameter in parameters)
|
||||
{
|
||||
restRequest.AddParameter(parameter.Key, parameter.Value);
|
||||
}
|
||||
}
|
||||
|
||||
if (method == Method.POST && body != null)
|
||||
{
|
||||
restRequest.AddJsonBody(body);
|
||||
}
|
||||
|
||||
var result = new RestClient(string.Format(baseUrl)).Execute(restRequest);
|
||||
return result;
|
||||
}
|
||||
|
||||
private TResponse Http<TResponse>(Method method, string relativeUri, Dictionary<string, string> parameters = null, Object body = null)
|
||||
{
|
||||
var result = Http(method, relativeUri, parameters, body);
|
||||
var response = JsonConvert.DeserializeObject<TResponse>(result.Content);
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
private TResponse GetAsync<TResponse>(string relativeUri, Dictionary<string, string> parameters = null)
|
||||
{
|
||||
return Http<TResponse>(Method.GET, relativeUri, parameters);
|
||||
}
|
||||
|
||||
private TResponse PostAsync<TResponse>(string relativeUri, Dictionary<string, string> parameters = null, Object body = null)
|
||||
{
|
||||
return Http<TResponse>(Method.POST, relativeUri, parameters, body);
|
||||
}
|
||||
|
||||
private void Post(string relativeUri, Dictionary<string, string> parameters = null, Object body = null)
|
||||
{
|
||||
Http(Method.POST, relativeUri, parameters, body);
|
||||
}
|
||||
|
||||
public JelentkezesResponseModel PostEloadasokTanuloszamossag(string intezmenyAzonosito, int eloadasId, int tanuloLetszam, int kiseroLetszam)
|
||||
{
|
||||
var body = new
|
||||
{
|
||||
IntezmenyAzonosito = intezmenyAzonosito,
|
||||
EloadasIdopont = eloadasId,
|
||||
TanulokSzama = tanuloLetszam,
|
||||
KiserokSzama = kiseroLetszam
|
||||
};
|
||||
|
||||
var response = PostAsync<JelentkezesResponseModel>("api/lep2/eloadasidopontresztvevointezmeny/external/jelentkezes", null, body);
|
||||
return response;
|
||||
}
|
||||
|
||||
public JelenletResponseModel PostEloadasokTanulojelenlet(string intezmenyAzonosito, int eloadasId, DataSet ds)
|
||||
{
|
||||
var body = new
|
||||
{
|
||||
IntezmenyAzonosito = intezmenyAzonosito,
|
||||
EloadasIdopont = eloadasId,
|
||||
TanuloLista = new List<JelenletRequestPartialModel>()
|
||||
};
|
||||
|
||||
foreach (DataRow row in ds.Tables[0].Rows)
|
||||
{
|
||||
body.TanuloLista.Add(new JelenletRequestPartialModel
|
||||
{
|
||||
TanuloId = row.Field<int>("TanuloId"),
|
||||
EvfolyamId = row.Field<int?>("EvfolyamId"),
|
||||
EvfolyamNev = row.Field<string>("EvfolyamNev"),
|
||||
OsztalyId = row.Field<int?>("OsztalyId"),
|
||||
OsztalyNev = row.Field<string>("OsztalyNev"),
|
||||
Megjelent = row.Field<string>("Megjelent") == "T",
|
||||
Torolt = row.Field<string>("Torolt") == "T"
|
||||
});
|
||||
}
|
||||
|
||||
var response = PostAsync<JelenletResponseModel>("api/lep2/eloadasidopontresztvevointezmeny/external/jelenlet", null, body);
|
||||
return response;
|
||||
}
|
||||
|
||||
public List<EloadasIdopontResponseModel> GetEloadasok(string intezmenyAzonosito, List<int> evfolyamList)
|
||||
{
|
||||
var body = new
|
||||
{
|
||||
IntezmenyAzonosito = intezmenyAzonosito,
|
||||
EvfolyamAzonositok = evfolyamList
|
||||
};
|
||||
|
||||
var response = PostAsync<List<EloadasIdopontResponseModel>>("api/lep2/eloadasidopontresztvevointezmeny/external/get", null, body);
|
||||
return response;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue