kreta/KretaWeb/Areas/ImportExport/Controllers/BaseTantargyfelosztasImportExportController.cs
2024-03-13 00:33:46 +01:00

196 lines
7.9 KiB
C#

using System.Collections.Generic;
using System.Linq;
using Kreta.BusinessLogic.HelperClasses;
using Kreta.BusinessLogic.HelperClasses.ImportCo;
using Kreta.BusinessLogic.Security;
using Kreta.Enums.ManualEnums.ImportExport;
using Kreta.Resources;
using Kreta.Web.Areas.ImportExport.Models.CommonModels;
using Kreta.Web.Security;
namespace Kreta.Web.Areas.ImportExport.Controllers
{
[MvcRoleClaimsAuthorize(true)]
[MvcRolePackageAuthorize(KretaClaimPackages.Adminisztrator.ClaimValue)]
public class BaseTantargyfelosztasImportExportController : BaseImportExportController
{
#region Public properties
public static string TantargyGridName => "TantargyGrid";
public static string TantargyGridRowTemplateName => "TantargyGridRowTemplate";
public static string OsztalyGridName => "OsztalyGrid";
public static string OsztalyGridRowTemplateName => "OsztalyGridRowTemplate";
public static string CsoportGridName => "CsoportGrid";
public static string CsoportGridRowTemplateName => "CsoportGridRowTemplate";
public static string TantargyfelosztasGridName => "TantargyfelosztasGrid";
public static string TantargyfelosztasGridRowTemplateName => "TantargyfelosztasGridRowTemplate";
#endregion Public properties
#region Import
protected static ImportInfoSummaryModel GetTantargyImportInfoSummary(List<TantargyImportJsonItemCo> importJsonItemList, List<TantargyItemCo> coList)
{
var importInfoSummary = new ImportInfoSummaryModel
{
ImportName = ImportExportTantargyfelosztasResource.Tantargy,
InsertRowCount = importJsonItemList?.Count(x => x.Operation == (int)ImportItemOperationEnum.Insert).ToString() ?? "0",
UpdateRowCount = "-",
DeleteRowCount = "-",
UnchangedRowCount = coList.Count.ToString(),
InvalidRowCount = "-"
};
return importInfoSummary;
}
protected static ImportInfoSummaryModel GetOsztalyImportInfoSummary(List<OsztalyImportJsonItemCo> importJsonItemList, List<OsztalyItemCo> coList)
{
var importInfoSummary = new ImportInfoSummaryModel
{
ImportName = ImportExportTantargyfelosztasResource.Osztaly,
InsertRowCount = importJsonItemList?.Count(x => x.Operation == (int)ImportItemOperationEnum.Insert).ToString() ?? "0",
UpdateRowCount = "-",
DeleteRowCount = "-",
UnchangedRowCount = coList.Count.ToString(),
InvalidRowCount = "-"
};
return importInfoSummary;
}
protected static ImportInfoSummaryModel GetCsoportImportInfoSummary(List<CsoportImportJsonItemCo> importJsonItemList, List<CsoportItemCo> coList)
{
var importInfoSummary = new ImportInfoSummaryModel
{
ImportName = ImportExportTantargyfelosztasResource.Csoport,
InsertRowCount = importJsonItemList?.Count(x => x.Operation == (int)ImportItemOperationEnum.Insert).ToString() ?? "0",
UpdateRowCount = "-",
DeleteRowCount = "-",
UnchangedRowCount = coList.Count.ToString(),
InvalidRowCount = "-"
};
return importInfoSummary;
}
protected List<TantargyImportItemModel> GetTantargyImportItemModelList(List<TantargyImportJsonItemCo> importJsonItemList, List<TantargyItemCo> coList)
{
var importItemModelList = new List<TantargyImportItemModel>();
if (importJsonItemList == null)
{
if (coList.Count == 0)
{
return importItemModelList;
}
importJsonItemList = new List<TantargyImportJsonItemCo>();
}
//NOTE: Hozzáadjuk azokat a az elemeket, amik az excel-ből jöttek!
foreach (TantargyImportJsonItemCo importJsonItem in importJsonItemList)
{
importItemModelList.Add(new TantargyImportItemModel
{
Nev = importJsonItem.Nev,
Operation = importJsonItem.Operation
});
}
//NOTE: Hozzáadjuk azokat a az elemeket, amik az adatbázisból jöttek!
foreach (TantargyItemCo co in coList)
{
if (!importJsonItemList.Select(x => x.Nev).Contains(co.Nev))
{
importItemModelList.Add(new TantargyImportItemModel
{
Nev = co.Nev,
Operation = (int)ImportItemOperationEnum.Default
});
}
}
return importItemModelList.OrderBy(x => x.Nev).ThenByDescending(x => x.OperationText).ToList();
}
protected List<OsztalyImportItemModel> GetOsztalyImportItemModelList(List<OsztalyImportJsonItemCo> importJsonItemList, List<OsztalyItemCo> coList)
{
var importItemModelList = new List<OsztalyImportItemModel>();
if (importJsonItemList == null)
{
if (coList.Count == 0)
{
return importItemModelList;
}
importJsonItemList = new List<OsztalyImportJsonItemCo>();
}
//NOTE: Hozzáadjuk azokat a az elemeket, amik az excel-ből jöttek!
foreach (OsztalyImportJsonItemCo importJsonItem in importJsonItemList)
{
importItemModelList.Add(new OsztalyImportItemModel
{
Nev = importJsonItem.OsztalyCsoportNev,
Operation = importJsonItem.Operation
});
}
//NOTE: Hozzáadjuk azokat a az elemeket, amik az adatbázisból jöttek!
foreach (OsztalyItemCo co in coList)
{
if (!importJsonItemList.Select(x => x.OsztalyCsoportNev).Contains(co.Nev))
{
importItemModelList.Add(new OsztalyImportItemModel
{
Nev = co.Nev,
Operation = (int)ImportItemOperationEnum.Default
});
}
}
return importItemModelList.OrderBy(x => x.Nev).ThenByDescending(x => x.OperationText).ToList();
}
protected List<CsoportImportItemModel> GetCsoportImportItemModelList(List<CsoportImportJsonItemCo> importJsonItemList, List<CsoportItemCo> coList)
{
var importItemModelList = new List<CsoportImportItemModel>();
if (importJsonItemList == null)
{
if (coList.Count == 0)
{
return importItemModelList;
}
importJsonItemList = new List<CsoportImportJsonItemCo>();
}
//NOTE: Hozzáadjuk azokat a az elemeket, amik az excel-ből jöttek!
foreach (CsoportImportJsonItemCo importJsonItem in importJsonItemList)
{
importItemModelList.Add(new CsoportImportItemModel
{
Nev = importJsonItem.OsztalyCsoportNev,
Operation = importJsonItem.Operation
});
}
//NOTE: Hozzáadjuk azokat a az elemeket, amik az adatbázisból jöttek!
foreach (CsoportItemCo co in coList)
{
if (!importJsonItemList.Select(x => x.OsztalyCsoportNev).Contains(co.Nev))
{
importItemModelList.Add(new CsoportImportItemModel
{
Nev = co.Nev,
Operation = (int)ImportItemOperationEnum.Default
});
}
}
return importItemModelList.OrderBy(x => x.Nev).ThenByDescending(x => x.OperationText).ToList();
}
#endregion Import
}
}