using System; using System.IO; using System.Linq; using System.Web; using System.Web.Mvc; using Kreta.BusinessLogic.Classes; using Kreta.BusinessLogic.Security; using Kreta.BusinessLogic.Utils; using Kreta.Enums.ManualEnums; using Kreta.Resources; using Kreta.Web.Areas.Tanulo.Models; using Kreta.Web.Configuration; using Kreta.Web.Helpers; using Kreta.Web.Security; namespace Kreta.Web.Classes { public static class Utils { public static string GetExcelTemplateFilePath(string fileName) { return GetServerFilePath(Constants.ImportExport.ExcelTemplateDirectory, fileName); } public static string GetExcelTemplateImportExportFilePath(string fileName) { return GetServerFilePath(Constants.ImportExport.ExcelTemplateImportExportDirectory, fileName); } public static string GetServerFilePath(string directory, string fileName) { string directoryPath = HttpContext.Current.Server.MapPath(directory); var directoryInfo = new DirectoryInfo(directoryPath); FileInfo fileInfo = directoryInfo.GetFiles().SingleOrDefault(x => x.Name.Equals(fileName, StringComparison.InvariantCultureIgnoreCase)); var fullName = fileInfo?.FullName; return fullName; } public static void TelefonSzamValidation(System.Web.Http.ModelBinding.ModelStateDictionary modelState, string telefonszam, int? telefonTipus, TelefonszamTulajdonosEnum telefonszamTulajdonos) { if (!string.IsNullOrWhiteSpace(telefonszam) && telefonTipus == null) { modelState.AddModelError("CimElerhetosegModel.TelefonTipus", ErrorResource.Telefon0TipusKotelezo.Replace("{0}", telefonszamTulajdonos.GetDisplayName(ClaimData.SelectedTanevID.Value))); } } public static void TajSzamValidation(System.Web.Http.ModelBinding.ModelStateDictionary modelState, string modelKey, string tajSzam) { var errorMessages = CommonUtils.TajSzamValidation(tajSzam); foreach (var errorMessage in errorMessages) { modelState.AddModelError(modelKey, errorMessage); } } public static int GetTanuloEletkor(TanuloModel tanuloModel) { TimeSpan span = DateTime.Now - tanuloModel.TanuloAlapAdatModel.SzuletesiIdo.Value; int tanuloEletkor = (DateTime.MinValue + span).Year - 1; return tanuloEletkor; } public static string GetAuthenticationTokenRedirectUrl(string baseUrl, string key) { var idpConfiguration = DependencyResolver.Current.GetService(); string redirectUrl = idpConfiguration.LoginEnabled ? baseUrl : new AuthenticationHelper(ConnectionTypeExtensions.GetSessionConnectionType()).CreateUrl(baseUrl, key, ClaimData.IntezmenyiDictionaryEnvironmentName); return redirectUrl; } /// /// Visszaadja a másik "lényeges" tanév id-t. /// Következő tanév esetén az aktuálisat, aktuális tanév esetén a következő tanévét, ha létezik. /// public static int? GetAnotherYearId() => ClaimData.IsKovTanev ? ClaimData.AktivTanevID : (ClaimData.IsActivTanev && ClaimData.KovTanevID.HasValue ? ClaimData.KovTanevID : null); } }