This commit is contained in:
skidoodle 2024-03-13 00:33:46 +01:00
commit e124a47765
19374 changed files with 9806149 additions and 0 deletions

View file

@ -0,0 +1,141 @@
using System;
using System.Linq;
using Kreta.Core.Enum;
using Kreta.Core.Exceptions;
using Kreta.Ellenorzo.Domain.VN.Common;
namespace Kreta.Ellenorzo.BL.VN.Logic
{
/// <summary>
/// Author: Madách Ferenc, Kovács Kornél (DevKornél), Érsek Zalán Created On: 2019.11.
/// </summary>
internal class ApiSecurityLogic
{
private readonly ApiSecurity _apiSecurity;
public int ApiSecurityVersion { get; private set; }
public bool IsJogosult { get; private set; } = false;
private const int BitParityPosition1 = 6;
private const int BitParityPosition2 = 54;
private const int SumOfRandomNumbersMinimum = 7;
private const int SumOfRandomNumbersMaximum = 38;
public ApiSecurityLogic(ApiSecurity apiSecurity)
{
_apiSecurity = apiSecurity;
if (_apiSecurity == null) ///Security disabled from config
{
IsJogosult = true;
return;
}
ApiSecurityVersion = int.Parse(_apiSecurity.SecurityKey.Substring(33, 3));///#7
}
internal void ThrowExceptionIfNotJogosult()
{
if (IsJogosult)
{
return;
}
if (_apiSecurity.SecurityKey != null && ApiSecurityVersion == 1)
{
IsJogosult = ApiSecurityValidate();
}
if (!IsJogosult)
{
throw new BlException(BlExceptionType.NincsJogosultsag);
}
}
private bool ApiSecurityValidate()
{
return _apiSecurity.SecurityKey.Length >= 150 &&
_apiSecurity.SecurityKey.Length <= 200 &&
IsBitParityValid() && ///#3
ContainsSignatureLastChars() && //#6
ValidateRandomNumbersSum() && ///#4
ValidateSignature() && ///#5
IsNoiseAlphaNumeric(); ///#9
}
private bool IsBitParityValid()
{
bool IsBinary(char c) => c == '0' || c == '1';
return IsBinary(_apiSecurity.SecurityKey[BitParityPosition1]) &&
IsBinary(_apiSecurity.SecurityKey[BitParityPosition2]) &&
_apiSecurity.SecurityKey[BitParityPosition1] != _apiSecurity.SecurityKey[BitParityPosition2];
}
private bool ValidateRandomNumbersSum()
{
int sumOfRandomNumbers = int.Parse(_apiSecurity.SecurityKey[8].ToString());
sumOfRandomNumbers += int.Parse(_apiSecurity.SecurityKey[30].ToString());
sumOfRandomNumbers += int.Parse(_apiSecurity.SecurityKey[36].ToString());
sumOfRandomNumbers += int.Parse(_apiSecurity.SecurityKey[43].ToString());
sumOfRandomNumbers += int.Parse(_apiSecurity.SecurityKey[49].ToString());
return sumOfRandomNumbers >= SumOfRandomNumbersMinimum && sumOfRandomNumbers <= SumOfRandomNumbersMaximum;
}
private bool ValidateSignature()
{
var secretChars = _apiSecurity.SecurityKey.ToCharArray();
/// #5-1
int step5_1_AsciiValue = _apiSecurity.SecurityKey[28];
int countRandomChar = _apiSecurity.Signature.ToCharArray().Count(s => s == _apiSecurity.SecurityKey[28]); ///#5-2
int constValue = 7234599;
int sumValue = countRandomChar + step5_1_AsciiValue + constValue;
string binaryRepresentation = Convert.ToString(sumValue, 2); ///#5-3
var arraySize = binaryRepresentation.Length;
for (int i = 0; i < 31; i++)
{
secretChars[90 - i] = i < arraySize ? binaryRepresentation[arraySize - i - 1] : '0';
}
///#5-4
int offset = int.Parse(secretChars[8].ToString());
var startBitPosition = 59;
void SwapPositions(int xIndex, int yIndex)
{
(secretChars[xIndex], secretChars[yIndex]) = (secretChars[yIndex], secretChars[xIndex]);
}
SwapPositions(startBitPosition + offset, startBitPosition + 31);
SwapPositions(startBitPosition + 10 + int.Parse(secretChars[30].ToString()), startBitPosition + offset);
SwapPositions(startBitPosition + int.Parse(secretChars[43].ToString()), startBitPosition + 17 + int.Parse(secretChars[49].ToString()));
SwapPositions(startBitPosition + int.Parse(secretChars[49].ToString()), startBitPosition + 30 - int.Parse(secretChars[49].ToString()));
var generatedSecretKey = new string(secretChars).Substring(startBitPosition, 32);
return _apiSecurity.SecurityKey.Substring(startBitPosition, 32) == generatedSecretKey;
}
public bool ContainsSignatureLastChars()
{
return _apiSecurity.SecurityKey.Substring(99, 3) == _apiSecurity.Signature.Substring(_apiSecurity.Signature.Length - 3, 3);
}
public bool IsNoiseAlphaNumeric() ///#9
{
int[] expectedNoisePositions = new int[6] { 42, 45, 94, 105, 114, 126 };
foreach (int i in expectedNoisePositions)
{
if (!char.IsLetterOrDigit(_apiSecurity.SecurityKey[i]))
{
return false;
}
}
return true;
}
}
}

View file

@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Kreta.BusinessLogic.Classes;
using Kreta.Ellenorzo.Domain.VN.Ertekeles;
namespace Kreta.Ellenorzo.BL.VN.Logic
{
public static class AtlagLogic
{
public static decimal? GetSubListAtlag(List<ErtekelesListResponse> ertekelesek)
=> (decimal?)ertekelesek.WeightedAverage(x => x.SzamErtek.Value, x => x.SulySzazalekErteke.Value, 2); // TODO ne legyen nullable
public static decimal GetSimpleAtlag(IEnumerable<decimal> ertekelesek)
=> Math.Round(ertekelesek.Average(), 2);
public static (decimal? SulyozottOsztalyzatOsszege, decimal? SulyozottOsztalyzatSzama, decimal? SulyozottAtlag) GetAtlagTuple(List<ErtekelesListResponse> ertekelesek)
=> GetSubListAtlagTuple(ErtekelesLogic.ListAtlagbaSzamitoErtekelesek(ertekelesek).ToList());
public static (decimal? SulyozottOsztalyzatOsszege, decimal? SulyozottOsztalyzatSzama, decimal? SulyozottAtlag) GetSubListAtlagTuple(List<ErtekelesListResponse> atlagbaSzamitoErtekelesek)
=> ((decimal? SulyozottOsztalyzatOsszege, decimal? SulyozottOsztalyzatSzama, decimal? SulyozottAtlag))atlagbaSzamitoErtekelesek.WeightedAverageTuple(x => x.SzamErtek.Value, x => x.SulySzazalekErteke.Value, 2);
private static (double? weightedValueSum, double? weightSum, double? weightAverage) WeightedAverageTuple<T>(this IEnumerable<T> recordEnumeration, Func<T, double> value, Func<T, double> weight, int? round = null)
{
if (!recordEnumeration.Any())
{
return (null, null, null);
}
var weightedValueSum = recordEnumeration.Sum(x => value(x) * weight(x));
var weightSum = recordEnumeration.Sum(weight);
var weightAverage = round.HasValue && round > 0 ? Math.Round(weightedValueSum / weightSum, round.Value) : weightedValueSum / weightSum;
return (weightedValueSum, weightSum, weightAverage);
}
}
}

View file

@ -0,0 +1,32 @@
using System.Collections.Generic;
using System.Linq;
using Kreta.Ellenorzo.Domain.VN.Ertekeles;
using Kreta.Ellenorzo.Domain.VN.Ertekeles.Atlag.TantargyiAtlag;
namespace Kreta.Ellenorzo.BL.VN.Logic
{
/// <summary>
/// Author: Kovács Kornél (DevKornél) Created On: 2019.10.
/// </summary>
public static class ErtekelesLogic
{
public static IEnumerable<ErtekelesListResponse> ListAtlagbaSzamitoErtekelesek(IEnumerable<ErtekelesListResponse> ertekelesek)
=> ertekelesek.Where(x => x.SzamErtek.HasValue && x.SulySzazalekErteke.HasValue);
public static List<AtlagAlakulasaResponse> GetAtlagAlakulasaIdoFuggvenyeben(TantargyiAtlagResponse tantargyiAtlag)
{
List<AtlagAlakulasaResponse> response = new List<AtlagAlakulasaResponse>();
List<ErtekelesListResponse> atlagbaSzamitoErtekelesek = ListAtlagbaSzamitoErtekelesek(tantargyiAtlag.Ertekelesek).OrderBy(e => e.KeszitesDatum).ToList();
for (int i = 0; i < atlagbaSzamitoErtekelesek.Count; ++i)
{
response.Add(new AtlagAlakulasaResponse
{
Atlag = AtlagLogic.GetSubListAtlag(atlagbaSzamitoErtekelesek.Take(i + 1).ToList()).Value,
Datum = atlagbaSzamitoErtekelesek[i].KeszitesDatum
});
}
return response;
}
}
}

View file

@ -0,0 +1,39 @@
using System.Collections.Generic;
using System.Linq;
using Kreta.Core.Enum;
using Kreta.Core.Exceptions;
using Kreta.Ellenorzo.Enums;
namespace Kreta.Ellenorzo.BL.VN.Logic
{
/// <summary>
/// Author: Kovács Kornél (DevKornél) Created On: 2019.05.
/// Felhasználói jogosultágkezelés logika
/// </summary>
internal static class FelhasznaloLogic
{
internal static bool IsJogosult(bool needExceptionJogosultsagHianyaban, IEnumerable<FelhasznaloSzerepkor> felhasznaloJogosultsagLista, params FelhasznaloSzerepkor[] szuksegesJogosultsagLista)
{
bool haveAllJogosultsag = true;
if (felhasznaloJogosultsagLista.ToList().Count > 0)
{
foreach (var szuksegesJogosultsag in szuksegesJogosultsagLista)
{
if (!felhasznaloJogosultsagLista.ToList().Contains(szuksegesJogosultsag))
{
haveAllJogosultsag = false;
}
}
}
else
{
needExceptionJogosultsagHianyaban = true;
haveAllJogosultsag = false;
}
return !haveAllJogosultsag && needExceptionJogosultsagHianyaban
? throw new BlException(BlExceptionType.NincsJogosultsag)
: haveAllJogosultsag;
}
}
}

View file

@ -0,0 +1,28 @@
using System.Collections.Generic;
using System.Linq;
using Kreta.Ellenorzo.BL.VN.OsztalyCsoport;
using Kreta.Ellenorzo.Domain.VN.Common;
using Kreta.Ellenorzo.Domain.VN.OsztalyCsoport;
using Kreta.Ellenorzo.Enums;
namespace Kreta.Ellenorzo.BL.VN.Logic
{
internal static class JogosultsagLogic
{
internal static List<int> ListHozzaferhetoAlkalmazottIds(DefaultConnectionParameters dcp)
{
var response = new List<int>();
if (FelhasznaloLogic.IsJogosult(false, dcp.JogosultsagLista, FelhasznaloSzerepkor.Tanulo) ||
FelhasznaloLogic.IsJogosult(false, dcp.JogosultsagLista, FelhasznaloSzerepkor.Gondviselo))
{
var tanuloOsztalyCsoportjai = OsztalyCsoportSubqueries.ListOsztalyCsoport(dcp, new OsztalyCsoportListRequest { TanuloIds = new List<int> { dcp.TanuloId } }).ToList();
var tanuloOsztalyfonokeiIds = tanuloOsztalyCsoportjai.Where(x => x.Osztalyfonok != null).Select(x => x.Osztalyfonok.Uid.Id).ToList();
var tanuloOsztalyfonokHelyetteseiIds = tanuloOsztalyCsoportjai.Where(x => x.OsztalyfonokHelyettes != null).Select(x => x.OsztalyfonokHelyettes.Uid.Id).ToList();
response.AddRange(tanuloOsztalyfonokeiIds.Union(tanuloOsztalyfonokHelyetteseiIds));
}
return response;
}
}
}

View file

@ -0,0 +1,53 @@
using System.Collections.Generic;
using System.Linq;
using Kreta.Enums;
namespace Kreta.Ellenorzo.BL.VN.Logic
{
/// <summary>
/// Author: Réti-Nagy Tamás Created On: 2019.11.
/// </summary>
internal static class OsztalyCsoportLogic
{
public static int GetSortIndexByOktatasNevelesiFeladat(OktatasiNevelesiFeladatEnum oktatasNevelesiFeladat)
{
return s_sortIndexByOktatasNevelesiFeladat.TryGetValue(oktatasNevelesiFeladat, out int value)
? value
: s_sortIndexByOktatasNevelesiFeladat.Values.Max() + 1;
}
private static readonly Dictionary<OktatasiNevelesiFeladatEnum, int> s_sortIndexByOktatasNevelesiFeladat = new Dictionary<OktatasiNevelesiFeladatEnum, int>
{
{ OktatasiNevelesiFeladatEnum.ovoda, 1 },
{ OktatasiNevelesiFeladatEnum.altalanos_iskola, 2 },
{ OktatasiNevelesiFeladatEnum.gimnazium, 3 },
{ OktatasiNevelesiFeladatEnum.szakkozepiskola, 4 },
{ OktatasiNevelesiFeladatEnum.szakiskola, 5 },
{ OktatasiNevelesiFeladatEnum.KonduktivPedagogiaiEllatas, 6 },
{ OktatasiNevelesiFeladatEnum.OvodaGyogypedagogia, 7 },
{ OktatasiNevelesiFeladatEnum.AltalanosIskolaGyogypedagogia, 8 },
{ OktatasiNevelesiFeladatEnum.keszsegfejleszto_iskola, 9 },
{ OktatasiNevelesiFeladatEnum.PedagogiaiSzakszolgaltatas, 11 },
{ OktatasiNevelesiFeladatEnum.KiegeszitoNemzetisegiNyelvoktatas, 12 },
{ OktatasiNevelesiFeladatEnum.szakgimnazium, 13 },
{ OktatasiNevelesiFeladatEnum.FejlesztoNevelesOktatas, 14 },
{ OktatasiNevelesiFeladatEnum.pedagogiai_szakmai_szolgaltatas, 15 },
{ OktatasiNevelesiFeladatEnum.koznevelesi_es_szakkepzesi_hidprogram, 16 },
{ OktatasiNevelesiFeladatEnum.ovoda_nemzetisegi_, 17 },
{ OktatasiNevelesiFeladatEnum.altalanos_iskola_nemzetisegi_, 18 },
{ OktatasiNevelesiFeladatEnum.gimnazium_nemzetisegi_, 19 },
{ OktatasiNevelesiFeladatEnum.szakgimnazium_nemzetisegi_, 20 },
{ OktatasiNevelesiFeladatEnum.szakkozepiskola_nemzetisegi_, 21 },
{ OktatasiNevelesiFeladatEnum.kollegium_nemzetisegi_, 22 },
{ OktatasiNevelesiFeladatEnum.MuveszetiSzakgimnazium, 100 },
{ OktatasiNevelesiFeladatEnum.AlapfokuMuveszetoktatas, 101 },
{ OktatasiNevelesiFeladatEnum.kollegium, 200 },
{ OktatasiNevelesiFeladatEnum.GyermekotthoniFeladatok, 201 },
{ OktatasiNevelesiFeladatEnum.UtazoGyogypedagogusiHalozat, 300 },
{ OktatasiNevelesiFeladatEnum.utazo_konduktori_halozat, 301 },
{ OktatasiNevelesiFeladatEnum.felnottoktatas, 400 },
{ OktatasiNevelesiFeladatEnum.felnottkepzes, 401 },
{ OktatasiNevelesiFeladatEnum.na, 1000 }
};
}
}

View file

@ -0,0 +1,50 @@
using System.Collections;
using Kreta.Core.Enum;
using Kreta.Core.Exceptions;
using Kreta.Ellenorzo.Domain.VN.Interfaces;
namespace Kreta.Ellenorzo.BL.VN.Logic
{
/// <summary>
/// Author: Kovács Kornél (DevKornél) Created On: 2019.06.
/// </summary>
internal static class RequestFilterLogic
{
public static TResponse CreateUidFilteredListResponse<TResponse, TRequest, TUid>(TResponse response, TRequest request) where TResponse : class, IEnumerable
where TRequest : class, IRequestUidFilter<TUid>
where TUid : class, IReadonlyUidRaw
{
int length = 0;
foreach (var element in response)
{
length++;
}
if (request.Uid == null)
{
return response;
}
if (request.IsCallerGetOnlyOneItem)
{
return length < 1
? throw new BlException(BlExceptionType.NemLetezoEntitas)
: length > 1 ? throw new BlException(BlExceptionType.TulSokVisszateresiElem) : response;
}
if (length > 1)
{
throw new BlException(BlExceptionType.TulSokVisszateresiElem);
}
return response;
}
public static TResponse CreateUidFilteredResponse<TResponse, TRequest, TUid>(TResponse response, TRequest request) where TResponse : class
where TRequest : class, IRequestUidFilter<TUid>
where TUid : class, IReadonlyUidRaw
{
return request.Uid == null || response == null ? throw new BlException(BlExceptionType.NemLetezoEntitas) : response;
}
}
}

View file

@ -0,0 +1,63 @@
using System.Collections.Generic;
using System.Linq;
using Kreta.Ellenorzo.BL.VN.Adatszotar;
using Kreta.Ellenorzo.Dao.VN.Tantargy;
using Kreta.Ellenorzo.Domain.VN.Adatszotar;
using Kreta.Ellenorzo.Domain.VN.Logic;
using Kreta.Ellenorzo.Domain.VN.Tantargy;
using Kreta.Ellenorzo.Enums.VN;
using Kreta.Enums;
namespace Kreta.Ellenorzo.BL.VN.Logic
{
/// <summary>
/// Author: Érsek Zalán Created On: 2019.09
/// </summary>
internal static class TantargyLogic
{
internal static readonly TantargyResponse MagatartasTantargy = new TantargyResponse(nameof(MagatartasSzorgalomTantargy.Magatartas),
EnumLogic.GetDisplayNameAttribute(MagatartasSzorgalomTantargy.Magatartas),
new Adatszotar<TargyKategoriaTipusEnum>(nameof(MagatartasSzorgalomTantargy.Magatartas),
EnumLogic.GetDisplayNameAttribute(MagatartasSzorgalomTantargy.Magatartas)), 0)
{
TantargyInTtf = false
};
internal static readonly TantargyResponse SzorgalomTantargy = new TantargyResponse(nameof(MagatartasSzorgalomTantargy.Szorgalom),
EnumLogic.GetDisplayNameAttribute(MagatartasSzorgalomTantargy.Szorgalom),
new Adatszotar<TargyKategoriaTipusEnum>(nameof(MagatartasSzorgalomTantargy.Szorgalom),
EnumLogic.GetDisplayNameAttribute(MagatartasSzorgalomTantargy.Szorgalom)), 1)
{
TantargyInTtf = false
};
internal static void RemoveOsztalyfonokiKategoriasTantargyak(List<TanultTantargyDao> tantargyList)
{
_ = tantargyList.RemoveAll(x => x.TargykategoriaId == (int)TargyKategoriaTipusEnum.osztalyfonoki_elet_es_palyatervezes && !x.ErtekelesBol);
}
internal static void OrderTantargyList(HashSet<TantargyResponse> tantargyList, int tanevId)
{
var targyKategoriaTipusById = AdatszotarSubqueries.GetTipusByIdDictionary((int)GeneratedAdatszotarTipusEnum.TargyKategoriaTipus, tanevId);
foreach (var tantargy in tantargyList.Where(x => x.Uid.Id != 0))
{
tantargy.TantargyKategoriaOrderIndex = targyKategoriaTipusById[tantargy.Kategoria.Uid.Id].Order ?? 10000;
tantargy.FotargyTantargyKategoriaOrderIndex = tantargy.FotargyKategoriaId.HasValue ? targyKategoriaTipusById[tantargy.FotargyKategoriaId.Value].Order ?? 10000 : (int?)null;
}
int index = 2;
foreach (TantargyResponse tantargy in tantargyList.Where(x => x.Uid.Id != 0) // A Magatartás és Szorgalom Id-ja 0, ezeket nem rendezzük, fix első két helyen vannak.
.OrderBy(x => x.SorSzam)
.ThenBy(x => x.IsFotargy ? x.TantargyKategoriaOrderIndex : x.FotargyTantargyKategoriaOrderIndex)
.ThenBy(x => x.IsFotargy ? x.Nev : x.FotargyNev)
.ThenBy(x => x.IsFotargy ? 0 : 1)
.ThenBy(x => x.Nev)
.ToList())
{
tantargy.SortIndex = index;
++index;
}
}
}
}

View file

@ -0,0 +1,8 @@
namespace Kreta.Ellenorzo.BL.VN.Logic
{
internal static class TanuloLogic
{
internal static string IsNullOrValue(string value) => string.IsNullOrWhiteSpace(value) ? null : " " + value;
}
}

View file

@ -0,0 +1,71 @@
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using Kreta.Core;
using Kreta.Core.Domain;
using Kreta.Core.Enum;
using Kreta.Core.Exceptions;
namespace Kreta.Ellenorzo.BL.VN.Logic
{
/// <summary>
/// Author: Kovács Kornél (DevKornél) Created On: 2019.06.
/// Validates the models with "DataAnnotationAttributes" and gives You the option
/// to create custom validation if model implements the "IValidatableObject" interface.
/// </summary>
internal class ValidatorLogic
{
private readonly List<ValidationResult> _errorList = new List<ValidationResult>();
private readonly bool _isValid = true;
internal ValidatorLogic(object instance)
{
var context = new ValidationContext(instance, serviceProvider: null, items: null);
_isValid = Validator.TryValidateObject(instance, context, _errorList, true);
}
internal ValidatorLogic(IEnumerable<object> instance)
{
foreach (var item in instance)
{
var context = new ValidationContext(item, serviceProvider: null, items: null);
if (!Validator.TryValidateObject(item, context, _errorList, true))
{
_isValid = false;
}
}
}
public static implicit operator string(ValidatorLogic validator) => validator.GetFirstUserFriendlyError();
internal BlException ConvertToValidationException()
{
var exception = new BlException(BlExceptionType.ModelValidacio);
var count = 1;
foreach (var error in _errorList)
{
var name = error.MemberNames.FirstOrDefault() ?? "custom_" + count;
exception.ErrorList.Add(new DetailedErrorItem(name, error.ErrorMessage, BlExceptionType.ModelValidacio));
count++;
}
return exception;
}
internal string GetFirstUserFriendlyError()
=> _errorList.Count > 0 ? _errorList[0].ErrorMessage : string.Empty;
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal string GetUserFriendlyError()
=> string.Join(Constants.General.LineSeparator, _errorList.Select(x => x.ErrorMessage).ToArray());
internal void ThrowExceptionIfModelIsNotvalid()
{
if (!_isValid)
{
throw ConvertToValidationException();
}
}
}
}