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,74 @@
using System;
using System.Data;
using System.Runtime.Caching;
using Kreta.DataAccessManual;
namespace Kreta.BusinessLogic.Classes.MobileApi.Common.Co
{
public class DefaultConnectionParameters
{
private class IntezmenyAdatok
{
public int TanevId { get; set; }
public int IntezmenyId { get; set; }
public string IntezmenyNev { get; set; }
}
public string IntezmenyAzonosito { get; }
public int TanevId { get; }
public int IntezmenyId { get; }
public string IntezmenyNev { get; }
public int FelhasznaloId { get; }
public DefaultConnectionParameters(MobileUser mobileUser)
{
this.FelhasznaloId = mobileUser.ActualUserId;
this.IntezmenyAzonosito = mobileUser.InstituteCode;
this.TanevId = mobileUser.SchoolYearId;
var intezmenyAdatok = GetIntezmenyAdatokFromCache();
this.IntezmenyId = intezmenyAdatok.IntezmenyId;
this.IntezmenyNev = intezmenyAdatok.IntezmenyNev;
}
private IntezmenyAdatok GetIntezmenyAdatokFromCache()
{
var cache = MemoryCache.Default;
string cacheKey = $"{IntezmenyAzonosito}_mobileIntezmenyAdatok";
var intezmenyAdatok = cache[cacheKey] as IntezmenyAdatok;
if (intezmenyAdatok == null)
{
intezmenyAdatok = GetIntezmenyAdatok();
var policy = new CacheItemPolicy
{
AbsoluteExpiration = new DateTimeOffset(DateTime.Now.AddMinutes(20))
};
cache.Set(cacheKey, intezmenyAdatok, policy);
}
return intezmenyAdatok;
}
private IntezmenyAdatok GetIntezmenyAdatok()
{
return Dal.MobileConnection.Run(IntezmenyAzonosito, TanevId, h =>
{
var intezmenyAdatok = h.IntezmenyDal().GetIntezmenyIdAndNevByAzonosito(IntezmenyAzonosito);
var returnIntezmenyAdatokObject = new IntezmenyAdatok
{
IntezmenyId = intezmenyAdatok.Tables[0].Rows[0].Field<int>("Id"),
IntezmenyNev = intezmenyAdatok.Tables[0].Rows[0].Field<string>("Nev")
};
return returnIntezmenyAdatokObject;
}, FelhasznaloId);
}
}
}

View file

@ -0,0 +1,70 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Kreta.BusinessLogic.Classes.MobileApi.Common.Enum;
namespace Kreta.BusinessLogic.Classes.MobileApi.Common.Co
{
public class MobileUser
{
const int MinimumIdentifierValue = 1;
public string InstituteCode { get; }
public int UserId { get; }
public int? TutelaryId { get; }
public int ActualUserId => this.TutelaryId ?? this.UserId;
public int SchoolYearId { get; }
public IEnumerable<MobileUserRole> Roles { get; }
public MobileUser(string instituteCode, int userId, int? tutelaryId, IEnumerable<MobileUserRole> roles, int schoolYearId)
{
if (string.IsNullOrWhiteSpace(instituteCode))
{
throw new ArgumentException($"{nameof(instituteCode)} cannot be null or whitespace");
}
this.InstituteCode = instituteCode;
if (userId < MinimumIdentifierValue)
{
throw new ArgumentException($"{nameof(userId)} must be greater or equal to {MinimumIdentifierValue}");
}
this.UserId = userId;
if (roles == null)
{
throw new ArgumentNullException(nameof(roles));
}
if (!roles.Any())
{
throw new ArgumentException($"User \"{instituteCode}/{userId}\" must have at least one role");
}
this.Roles = roles;
if (tutelaryId != null)
{
if (tutelaryId < MinimumIdentifierValue)
{
throw new ArgumentException($"{nameof(tutelaryId)} must be greater or equal to {MinimumIdentifierValue}");
}
if (!roles.Contains(MobileUserRole.Tutelary))
{
throw new ArgumentException($"{nameof(roles)} must contain {MobileUserRole.Tutelary} because {nameof(tutelaryId)} is not null");
}
}
this.TutelaryId = tutelaryId;
this.SchoolYearId = schoolYearId;
}
}
}

View file

@ -0,0 +1,9 @@
namespace Kreta.BusinessLogic.Classes.MobileApi.Common.Enum
{
public enum MobileUserRole
{
Student,
Tutelary,
Teacher
}
}