using System; using System.Collections.Generic; using System.Linq; using Kreta.BusinessLogic.Classes; using Kreta.Client.CoreApi; using Kreta.Client.CoreApi.Response; using Kreta.Core; using Kreta.Core.ConnectionType; using Kreta.Core.Validation.Exceptions; using Kreta.Core.Validation.Exceptions.Enum; using Kreta.DataAccessManual; using Kreta.DataAccessManual.Util; using Kreta.Enums.ManualEnums; namespace Kreta.BusinessLogic.Helpers { public class EszkozIgenylesHelper : LogicBase { public EszkozIgenylesHelper(IConnectionType connectionType) : base(connectionType) { } public int EszkozIgenylesInsert(ICoreApiClient coreApiClient, EszkozIgenylesCreateDto dto, string intezmenyGuid, int tanevSorszam) { try { var response = coreApiClient.EszkozIgenylesInsert(dto, intezmenyGuid, tanevSorszam); return response.NewId; } catch (Exception e) { throw new ValidationException(ValidationErrorType.Undefined, e.Message); } } public void EszkozIgenylesUpdate(ICoreApiClient coreApiClient, EszkozIgenylesUpdateDto dto, string intezmenyGuid, int tanevSorszam) { try { var response = coreApiClient.EszkozIgenylesUpdate(dto, intezmenyGuid, tanevSorszam); } catch (Exception e) { throw new ValidationException(ValidationErrorType.Undefined, e.Message); } } public List EszkozIgenylesGet(ICoreApiClient coreApiClient, string intezmenyGuid, int tanevSorszam, int? alkalmazottId, int? gondviseloId) { try { var result = coreApiClient.EszkozIgenylesGet(intezmenyGuid, tanevSorszam); if (alkalmazottId.HasValue) { result = result.Where(x => x.AlkalmazottId == alkalmazottId.Value).ToList(); } if (gondviseloId.HasValue) { result = result.Where(x => x.GondviseloId == gondviseloId.Value).ToList(); } return result; } catch (Exception e) { throw new ValidationException(ValidationErrorType.Undefined, e.Message); } } public bool IsEszkozKiosztva(int tanuloId) { return Dal.CustomConnection.Run(ConnectionType, h => { var eszkozIgenyles = h.EszkozigenylesDal(); var dataSet = eszkozIgenyles.IsEszkozKiosztva(IntezmenyId, TanevId, tanuloId); if (dataSet.Tables[0].Rows.Count < 1) { return false; } return SDAConvert.ToBooleanFromTF(dataSet.Tables[0].Rows[0]["C_ISESZKOZKIOSZTVA"]); }); } public string EszkozUgyintezesUrl() { return Dal.CustomConnection.Run(ConnectionType, (h) => { var intezmenyConfigHelper = new IntezmenyConfigHelper(new DalHandlerConnectionType(ConnectionType, h)); var eszkozUgyintezesUrl = intezmenyConfigHelper.GetIntezmenyConfig(IntezmenyConfigModulEnum.EszkozUgyintezes, IntezmenyConfigTipusEnum.Url); return eszkozUgyintezesUrl; }); } } }