118 lines
4.3 KiB
C#
118 lines
4.3 KiB
C#
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;
|
|
}
|
|
}
|
|
}
|