init
This commit is contained in:
commit
e124a47765
19374 changed files with 9806149 additions and 0 deletions
|
@ -0,0 +1,201 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.Caching;
|
||||
using Kreta.BusinessLogic.Classes;
|
||||
using Kreta.BusinessLogic.HelperClasses;
|
||||
using Kreta.BusinessLogic.HelperClasses.ImportCo;
|
||||
using Kreta.BusinessLogic.Logic;
|
||||
using Kreta.Core;
|
||||
using Kreta.Core.ConnectionType;
|
||||
using Kreta.DataAccessManual;
|
||||
using Kreta.Enums.ManualEnums;
|
||||
using Kreta.Enums.ManualEnums.ImportExport;
|
||||
using Kreta.Resources;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Kreta.BusinessLogic.Helpers.ImportExport
|
||||
{
|
||||
public class TanmenetImportExportHelper : LogicBase
|
||||
{
|
||||
#region Fields
|
||||
|
||||
private readonly string _importObjectCacheKey;
|
||||
|
||||
#endregion Fields
|
||||
|
||||
#region Properties
|
||||
|
||||
public static Dictionary<int, string> ImportHeaderList => new Dictionary<int, string>
|
||||
{
|
||||
{ 00, ImportExportTanmenetResource.ImportHeaderNameOraszam },
|
||||
{ 01, ImportExportTanmenetResource.ImportHeaderNameTema }
|
||||
};
|
||||
|
||||
public TanmenetImportCo ImportCo
|
||||
{
|
||||
get => (TanmenetImportCo)Cache.Get(_importObjectCacheKey);
|
||||
set
|
||||
{
|
||||
if (ImportCo != null)
|
||||
{
|
||||
Cache.Remove(_importObjectCacheKey);
|
||||
}
|
||||
|
||||
Cache.Add(_importObjectCacheKey, value, new CacheItemPolicy { SlidingExpiration = TimeSpan.FromMinutes(30) });
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Properties
|
||||
|
||||
#region Constructors
|
||||
|
||||
public TanmenetImportExportHelper(IConnectionType connectionType) : base(connectionType)
|
||||
{
|
||||
_importObjectCacheKey = $"{nameof(TanmenetImportCo)}_{IntezmenyId}_{FelhasznaloId}_ImportObjectCacheKey";
|
||||
}
|
||||
|
||||
#endregion Constructors
|
||||
|
||||
public void SetImportCo(List<List<string>> importData, int tantargyfelosztasId, bool isFromSzervezet)
|
||||
{
|
||||
var importCo = GetImportCoFromImportData(importData, tantargyfelosztasId, isFromSzervezet);
|
||||
importCo.ImportMuvelet = (int)ImportMuveletEnum.DeleteAndInsert;
|
||||
|
||||
SetNemImportalhatoSorokByValidation(importCo);
|
||||
|
||||
SetOperationAndNemImportalhatoSorokByOperation(importCo);
|
||||
|
||||
var mainImportJsonItemList = new List<TanmenetImportJsonItemCo>(importCo.MainImportItemList.Select(x => new TanmenetImportJsonItemCo(x, importCo.Tantargyfelosztas, TanevId, IntezmenyId, FelhasznaloId)));
|
||||
importCo.MainImportJsonItemList = mainImportJsonItemList;
|
||||
|
||||
ImportCo = importCo;
|
||||
}
|
||||
|
||||
private static void SetNemImportalhatoSorokByValidation(TanmenetImportCo importCo)
|
||||
{
|
||||
Dictionary<int, List<ValidationResult>> validationResultDictionary = importCo.Validate();
|
||||
|
||||
//NOTE: Azokat a sorokat, amelyek hibásak beletesszük a NemImportalhatoItemList-be!
|
||||
foreach (TanmenetImportItemCo importItem in importCo.MainImportItemList.Where(x => validationResultDictionary.Keys.Contains(x.LineNumber)))
|
||||
{
|
||||
IEnumerable<ValidationResult> validationResultList = validationResultDictionary[importItem.LineNumber];
|
||||
importItem.ErrorList = validationResultList.Select(x => x.ErrorMessage).ToList();
|
||||
importCo.NemImportalhatoItemList.Add(importItem);
|
||||
}
|
||||
|
||||
//NOTE: Azokat a sorokat, amelyek bekerültek a NemImportalhatoItemList-be, azokat kiveszzük a MainImportItemList-ből!
|
||||
importCo.MainImportItemList.RemoveRange(importCo.NemImportalhatoItemList);
|
||||
}
|
||||
|
||||
private void SetOperationAndNemImportalhatoSorokByOperation(TanmenetImportCo importCo)
|
||||
{
|
||||
foreach (TanmenetImportItemCo importItem in importCo.MainImportItemList)
|
||||
{
|
||||
importItem.Operation = (int)ImportItemOperationEnum.Insert;
|
||||
}
|
||||
}
|
||||
|
||||
private TanmenetImportCo GetImportCoFromImportData(List<List<string>> importData, int tantargyfelosztasId, bool isFromSzervezet)
|
||||
{
|
||||
var tantargyfelosztasCoList = new TantargyFelosztasHelper(ConnectionType).GetTantargyfelosztasCoList(alkalmazottId: FelhasznaloId, isFromSzervezet: isFromSzervezet);
|
||||
|
||||
if (isFromSzervezet)
|
||||
{
|
||||
var szervezetHelper = new SzervezetHelper(ConnectionType);
|
||||
var alkalmazottSzervezetId = szervezetHelper.GetAlkalmazottSzervezetId(FelhasznaloId);
|
||||
var lathatoSzervezetIdList = szervezetHelper.GetLathatoSzervezetIdList(alkalmazottSzervezetId, SzervezetAdatokHalmazaEnum.SzervezetEsAlSzervezetek);
|
||||
|
||||
tantargyfelosztasCoList.RemoveAll(x =>
|
||||
{
|
||||
if (x.SzervezetId.IsEntityId())
|
||||
{
|
||||
return !lathatoSzervezetIdList.Contains(x.SzervezetId.Value);
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
var importCo = new TanmenetImportCo
|
||||
{
|
||||
Tantargyfelosztas = tantargyfelosztasCoList.Single(x => x.Id == tantargyfelosztasId),
|
||||
};
|
||||
|
||||
var tanmenetCoList = new TanmenetHelper(ConnectionType).GetTanmenetCoList(FelhasznaloId).Where(x => x.TantargyfelosztasId == tantargyfelosztasId).ToList();
|
||||
|
||||
var lineNumber = 1;
|
||||
foreach (var importDataRow in importData.Skip(1))
|
||||
{
|
||||
var importItemCo = new TanmenetImportItemCo
|
||||
{
|
||||
LineNumber = lineNumber,
|
||||
|
||||
OraszamImportData = importDataRow[ImportHeaderList.GetKeyByUniqueValue(ImportExportTanmenetResource.ImportHeaderNameOraszam)],
|
||||
TemaImportData = importDataRow[ImportHeaderList.GetKeyByUniqueValue(ImportExportTanmenetResource.ImportHeaderNameTema)]
|
||||
};
|
||||
|
||||
if (importCo.Tantargyfelosztas != null && importItemCo.OraSorszam.IsNotNullAndPositive())
|
||||
{
|
||||
importItemCo.Tanmenet = tanmenetCoList.SingleOrDefault(x =>
|
||||
x.TantargyfelosztasId == importCo.Tantargyfelosztas.Id &&
|
||||
x.OraSorszam == importItemCo.OraSorszam
|
||||
);
|
||||
}
|
||||
|
||||
var md5HashInput = importItemCo.OraSorszam?.ToString();
|
||||
importItemCo.CompareHash = ImportExportHelper.GetMd5Hash(md5HashInput);
|
||||
|
||||
importCo.MainImportItemList.Add(importItemCo);
|
||||
|
||||
lineNumber++;
|
||||
}
|
||||
|
||||
return importCo;
|
||||
}
|
||||
|
||||
#region Template
|
||||
|
||||
public MemoryStream GetTemplate()
|
||||
{
|
||||
List<SimpleExportColumnCo> simpleExportColumnCos = SimpleExportLogic.GetSimpleExportColumnCos<TanmenetItemCo>(TanmenetItemCo.TanmenetExportAttributeId, GetDefaultDropDownColumnSourceDictionary());
|
||||
return SimpleExportLogic.GetTemplate(ImportExportTanmenetResource.ImportDefaultSheetName, simpleExportColumnCos);
|
||||
}
|
||||
|
||||
#endregion Template
|
||||
|
||||
#region Export
|
||||
|
||||
public MemoryStream GetExport(int tantargyfelosztasId)
|
||||
{
|
||||
List<TanmenetItemCo> coList = new TanmenetHelper(ConnectionType).GetTanmenetCoList(FelhasznaloId).Where(x => x.TantargyfelosztasId == tantargyfelosztasId).ToList();
|
||||
List<SimpleExportColumnCo> simpleExportColumnCos = SimpleExportLogic.GetSimpleExportColumnCos<TanmenetItemCo>(TanmenetItemCo.TanmenetExportAttributeId, GetDefaultDropDownColumnSourceDictionary());
|
||||
return SimpleExportLogic.GetExport(ImportExportTanmenetResource.ImportDefaultSheetName, simpleExportColumnCos, coList, TanevId);
|
||||
}
|
||||
|
||||
public MemoryStream GetNemImportalhatoSorokExport()
|
||||
{
|
||||
List<TanmenetImportItemCo> coList = ImportCo.NemImportalhatoItemList;
|
||||
List<SimpleExportColumnCo> simpleExportColumnCos = SimpleExportLogic.GetSimpleExportColumnCos<TanmenetImportItemCo>(TanmenetImportItemCo.NemImportalhatoSorokExportAttributeId, GetDefaultDropDownColumnSourceDictionary());
|
||||
return ImportExportHelper.NemImportalhatoSorokExport(ImportExportTanmenetResource.ImportDefaultSheetName, simpleExportColumnCos, coList, TanevId);
|
||||
}
|
||||
|
||||
#endregion Export
|
||||
|
||||
public void Import(object importJsonObject, int importMuvelet, int tantargyId, int osztalyCsoportId)
|
||||
{
|
||||
string importJson = JsonConvert.SerializeObject(importJsonObject);
|
||||
bool isTorles = importMuvelet == (int)ImportMuveletEnum.DeleteAndInsert;
|
||||
Dal.CustomConnection.Run(ConnectionType, dalHandler => dalHandler.ImportExportDal().TanmenetImport(IntezmenyId, TanevId, FelhasznaloId, importJson, isTorles, tantargyId, osztalyCsoportId));
|
||||
}
|
||||
|
||||
private Dictionary<string, IList<string>> GetDefaultDropDownColumnSourceDictionary()
|
||||
{
|
||||
//NOTE: Create dropdown lists
|
||||
var dropDownColumnSourceDictionary = new Dictionary<string, IList<string>>();
|
||||
return dropDownColumnSourceDictionary;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue