71 lines
3.2 KiB
C#
71 lines
3.2 KiB
C#
using System.Collections.Generic;
|
|
using System.Data;
|
|
using Kreta.BusinessLogic.Classes.MobileApi.Naplo.V2.Co.Get.Tanmenet;
|
|
using Kreta.BusinessLogic.Classes.MobileApi.Naplo.V2.Logic;
|
|
using Kreta.Core.Validation.Exceptions;
|
|
using Kreta.Core.Validation.Exceptions.Enum;
|
|
using Kreta.DataAccessManual.Interfaces;
|
|
|
|
namespace Kreta.BusinessLogic.Classes.MobileApi.Naplo.V2.SubqueriesRepo
|
|
{
|
|
public static class TanmenetSubqueries
|
|
{
|
|
public static List<TanmenetGetResponseCo> ListTanmenet(IDalHandler h, int teacherId, int tanevId, int intezmenyId, string intezmenyAzonosito, TanmenetGetRequestCo request)
|
|
{
|
|
var allowedRequestRecordLength = 10;
|
|
if (request.Key.Length > allowedRequestRecordLength)
|
|
{
|
|
throw new ValidationException(ValidationErrorType.Undefined, $"Hiba történt, {nameof(allowedRequestRecordLength)}={allowedRequestRecordLength}!");
|
|
}
|
|
|
|
var errors = new List<ValidationExceptionItem>();
|
|
var tanarHelyettesitesLogic = new HelyettesitesLogic.Tanar(teacherId, tanevId, intezmenyId, intezmenyAzonosito, null);
|
|
|
|
for (int i = 0; i < request.Key.Length; i++)
|
|
{
|
|
var tanmenetKey = request.Key[i];
|
|
|
|
if (tanmenetKey.FeltoltoTanarId != teacherId && !tanarHelyettesitesLogic.IsHelyettesito(tanmenetKey.OsztalyCsoportId, tanmenetKey.TantargyId))
|
|
{
|
|
errors.Add(new ValidationExceptionItem(i.ToString(), $"Nincs jogosultsága, csak a saját vagy helyettesítési tanmenet kérdezhető le!"));
|
|
}
|
|
}
|
|
|
|
if (errors.Count > 0)
|
|
{
|
|
throw new ValidationException(ValidationErrorType.Undefined, "Hiba történt!", errors);
|
|
}
|
|
|
|
var response = new List<TanmenetGetResponseCo>();
|
|
var tanmenetDal = h.Tanmenet();
|
|
|
|
foreach (var tanmenetKey in request.Key)
|
|
{
|
|
var tanmenetItems = new List<TanmenetItemGetResponseCo>();
|
|
var tanmenetItemDt = tanmenetDal.GetTanmenetek(tanmenetKey.TantargyId, tanmenetKey.OsztalyCsoportId, tanmenetKey.FeltoltoTanarId).Tables[0];
|
|
foreach (DataRow tanmenetItem in tanmenetItemDt.Rows)
|
|
{
|
|
tanmenetItems.Add(new TanmenetItemGetResponseCo
|
|
{
|
|
Id = tanmenetItem.Field<int>("ID"),
|
|
EvesOraszam = tanmenetItem.Field<int>("Oraszam"),
|
|
Tema = tanmenetItem.Field<string>("Tema"),
|
|
Megjegyzes = tanmenetItem.Field<string>("Megjegyzes"),
|
|
Nev = tanmenetItem.Field<string>("Nev"),
|
|
RovidNev = tanmenetItem.Field<string>("RovidNev")
|
|
});
|
|
}
|
|
|
|
response.Add(new TanmenetGetResponseCo
|
|
{
|
|
OsztalyCsoportId = tanmenetKey.OsztalyCsoportId,
|
|
TantargyId = tanmenetKey.TantargyId,
|
|
FeltoltoTanarId = tanmenetKey.FeltoltoTanarId,
|
|
Items = tanmenetItems
|
|
});
|
|
}
|
|
|
|
return response;
|
|
}
|
|
}
|
|
}
|