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 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(); 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(); var tanmenetDal = h.Tanmenet(); foreach (var tanmenetKey in request.Key) { var tanmenetItems = new List(); 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("ID"), EvesOraszam = tanmenetItem.Field("Oraszam"), Tema = tanmenetItem.Field("Tema"), Megjegyzes = tanmenetItem.Field("Megjegyzes"), Nev = tanmenetItem.Field("Nev"), RovidNev = tanmenetItem.Field("RovidNev") }); } response.Add(new TanmenetGetResponseCo { OsztalyCsoportId = tanmenetKey.OsztalyCsoportId, TantargyId = tanmenetKey.TantargyId, FeltoltoTanarId = tanmenetKey.FeltoltoTanarId, Items = tanmenetItems }); } return response; } } }