init
This commit is contained in:
commit
e124a47765
19374 changed files with 9806149 additions and 0 deletions
|
@ -0,0 +1,246 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using Kreta.BusinessLogic.HelperClasses;
|
||||
using Kreta.BusinessLogic.HelperClasses.ImportCo;
|
||||
using Kreta.BusinessLogic.Helpers;
|
||||
using Kreta.BusinessLogic.Helpers.ImportExport;
|
||||
using Kreta.BusinessLogic.Security;
|
||||
using Kreta.Core;
|
||||
using Kreta.Enums.ManualEnums;
|
||||
using Kreta.Enums.ManualEnums.ImportExport;
|
||||
using Kreta.Resources;
|
||||
using Kreta.Web.Areas.ImportExport.Models.CommonModels;
|
||||
using Kreta.Web.Areas.ImportExport.Models.TanmenetImportExport;
|
||||
using Kreta.Web.Classes;
|
||||
using Kreta.Web.Helpers;
|
||||
using Kreta.Web.Models.EditorTemplates;
|
||||
using Kreta.Web.Security;
|
||||
|
||||
namespace Kreta.Web.Areas.ImportExport.Controllers
|
||||
{
|
||||
[MvcRoleClaimsAuthorize(true)]
|
||||
[MvcRolePackageDenyAuthorize(KretaClaimPackages.IsOnlyAlkalmozott.ClaimValue)]
|
||||
[MvcRolePackageAuthorize(TanevEnum.AktTanev, KretaClaimPackages.Tanar.ClaimValue)]
|
||||
public abstract class BaseTanmenetImportExportController : BaseImportExportController
|
||||
{
|
||||
#region Properties
|
||||
|
||||
public static string GridName => "TanmenetGrid";
|
||||
public static string GridRowTemplateName => "TanmenetGridRowTemplate";
|
||||
|
||||
public static string JavascriptHelperClassName => "TanmenetImportExportHelper";
|
||||
|
||||
protected IKretaAuthorization Authorization { get; }
|
||||
|
||||
#endregion Properties
|
||||
|
||||
#region Constructors
|
||||
|
||||
public BaseTanmenetImportExportController(IUploadFileValidator uploadFileValidator, IKretaAuthorization authorization)
|
||||
{
|
||||
UploadFileValidator = uploadFileValidator ?? throw new ArgumentNullException(nameof(uploadFileValidator));
|
||||
Authorization = authorization ?? throw new ArgumentNullException(nameof(authorization));
|
||||
}
|
||||
|
||||
#endregion Constructors
|
||||
|
||||
#region Sablon
|
||||
|
||||
public ActionResult DownloadTemplate()
|
||||
{
|
||||
MemoryStream memoryStream = new TanmenetImportExportHelper(ConnectionTypeExtensions.GetSessionConnectionType()).GetTemplate();
|
||||
return new FileStreamResult(memoryStream, Core.Constants.ContentTypes.Xlsx) { FileDownloadName = ImportExportTanmenetResource.ImportSablonFileName };
|
||||
}
|
||||
|
||||
#endregion Sablon
|
||||
|
||||
#region Export
|
||||
|
||||
[HttpPost]
|
||||
[MvcValidateAjaxAntiForgeryToken]
|
||||
public string Export(int? exportTantargyfelosztasId)
|
||||
{
|
||||
var errorResult = new List<string>();
|
||||
if (!exportTantargyfelosztasId.IsEntityId())
|
||||
{
|
||||
errorResult.Add(ImportExportTanmenetResource.InvalidFoglalkozas);
|
||||
}
|
||||
|
||||
if (errorResult.Count > 0)
|
||||
{
|
||||
return string.Join("<br />", errorResult);
|
||||
}
|
||||
|
||||
MemoryStream memoryStream = new TanmenetImportExportHelper(ConnectionTypeExtensions.GetSessionConnectionType()).GetExport(exportTantargyfelosztasId.Value);
|
||||
return GetExportFileString(memoryStream);
|
||||
}
|
||||
|
||||
public string NemImportalhatoSorokExport()
|
||||
{
|
||||
MemoryStream memoryStream = new TanmenetImportExportHelper(ConnectionTypeExtensions.GetSessionConnectionType()).GetNemImportalhatoSorokExport();
|
||||
return GetExportFileString(memoryStream);
|
||||
}
|
||||
|
||||
#endregion Export
|
||||
|
||||
#region Import
|
||||
|
||||
[NonAction]
|
||||
public JsonResult UploadFile(HttpPostedFileBase importFile, int? tantargyfelosztasId, bool isFromSzervezet)
|
||||
{
|
||||
UploadFileValidator.ValidateImportFile(importFile);
|
||||
|
||||
var errorResult = new List<string>();
|
||||
|
||||
if (tantargyfelosztasId == null)
|
||||
{
|
||||
errorResult.Add(ImportExportTanmenetResource.InvalidFoglalkozas);
|
||||
}
|
||||
|
||||
Dictionary<int, string> importHeaderList = TanmenetImportExportHelper.ImportHeaderList;
|
||||
List<List<string>> importData = ImportExportHelper.GetImportDataFromExcel(importFile.InputStream, importHeaderList, out List<string> fileErrorResultList);
|
||||
errorResult.AddRange(fileErrorResultList);
|
||||
|
||||
if (errorResult.Count > 0)
|
||||
{
|
||||
JsonResult errorJson = ThrowCustomError(errorResult);
|
||||
return errorJson;
|
||||
}
|
||||
|
||||
new TanmenetImportExportHelper(ConnectionTypeExtensions.GetSessionConnectionType()).SetImportCo(importData, tantargyfelosztasId.Value, isFromSzervezet);
|
||||
|
||||
return Json(null);
|
||||
}
|
||||
|
||||
public ActionResult OpenImportPreviewPopup()
|
||||
{
|
||||
TanmenetImportCo importCo = new TanmenetImportExportHelper(ConnectionTypeExtensions.GetSessionConnectionType()).ImportCo;
|
||||
List<TanmenetItemCo> coList = new TanmenetHelper(ConnectionTypeExtensions.GetSessionConnectionType()).GetTanmenetCoList(ClaimData.FelhasznaloId).Where(x => x.TantargyfelosztasId == importCo.Tantargyfelosztas.Id).ToList();
|
||||
|
||||
var importInfoModel = new TanmenetImportInfoModel
|
||||
{
|
||||
ImportInfoSummaryList = new ImportInfoSummaryListModel
|
||||
{
|
||||
ImportInfoSummaryModelList = new List<ImportInfoSummaryModel>
|
||||
{
|
||||
GetImportInfoSummary(importCo, coList)
|
||||
}
|
||||
},
|
||||
MainImportItemList = new TanmenetImportItemListModel
|
||||
{
|
||||
ImportItemModelList = GetImportItemModelList(importCo, coList)
|
||||
},
|
||||
NemImportalhatoItemList = new TanmenetImportNemImportalhatoItemListModel
|
||||
{
|
||||
NemImportalhatoItemModelList = GetNemImportalhatoItemModelList(importCo.NemImportalhatoItemList)
|
||||
}
|
||||
};
|
||||
|
||||
var popUpModel = new PopUpModel(importInfoModel, $"~/Areas/ImportExport/Views/TanmenetImportExport/{ImportPreviewPopupName}.cshtml");
|
||||
popUpModel.AddCancelBtn(popUpModel, "KretaWindowHelper.destroyAllWindow");
|
||||
popUpModel.AddBtn(popUpModel, "ImportBtnOk", CommonResource.Importalas, $"{JavascriptHelperClassName}.import", "BtnOk", setDisabledAfterClick: true);
|
||||
popUpModel.AddBtn(popUpModel, "NemImportalhatoSorokExportBtnOk", ImportExportCommonResource.NemImportalhatoSorokExportalasa, $"{JavascriptHelperClassName}.nemImportalhatoSorokExport", "BtnOk");
|
||||
return PartialView(Constants.General.PopupView, popUpModel);
|
||||
}
|
||||
|
||||
private static ImportInfoSummaryModel GetImportInfoSummary(TanmenetImportCo importCo, List<TanmenetItemCo> coList)
|
||||
{
|
||||
List<TanmenetImportJsonItemCo> mainImportJsonItemList = importCo.MainImportJsonItemList;
|
||||
int insertRowCount = mainImportJsonItemList?.Count(x => x.Operation == (int)ImportItemOperationEnum.Insert) ?? 0;
|
||||
int deleteRowCount = coList.Count;
|
||||
int invalidRowCount = importCo.NemImportalhatoItemList.Count;
|
||||
var importInfoSummary = new ImportInfoSummaryModel
|
||||
{
|
||||
ImportName = ImportExportTanmenetResource.ImportDefaultSheetName,
|
||||
InsertRowCount = insertRowCount.ToString(),
|
||||
UpdateRowCount = "-",
|
||||
DeleteRowCount = deleteRowCount.ToString(),
|
||||
UnchangedRowCount = "-",
|
||||
InvalidRowCount = invalidRowCount.ToString()
|
||||
};
|
||||
|
||||
return importInfoSummary;
|
||||
}
|
||||
|
||||
private List<TanmenetImportItemModel> GetImportItemModelList(TanmenetImportCo importCo, List<TanmenetItemCo> coList)
|
||||
{
|
||||
var importItemModelList = new List<TanmenetImportItemModel>();
|
||||
List<TanmenetImportJsonItemCo> mainImportJsonItemList = importCo.MainImportJsonItemList;
|
||||
if (mainImportJsonItemList == null)
|
||||
{
|
||||
if (!(coList.Count > 0))
|
||||
{
|
||||
return importItemModelList;
|
||||
}
|
||||
|
||||
mainImportJsonItemList = new List<TanmenetImportJsonItemCo>();
|
||||
}
|
||||
|
||||
//NOTE: Hozzáadjuk azokat a az elemeket, amik az excel-ből jöttek!
|
||||
foreach (TanmenetImportJsonItemCo importJsonItem in mainImportJsonItemList)
|
||||
{
|
||||
importItemModelList.Add(new TanmenetImportItemModel
|
||||
{
|
||||
OraSorszam = importJsonItem.OraSorszam.ToString(),
|
||||
Tema = importJsonItem.Tema ?? string.Empty,
|
||||
Operation = importJsonItem.Operation
|
||||
});
|
||||
}
|
||||
|
||||
//NOTE: Hozzáadjuk azokat a az elemeket, amik az adatbázisból jöttek!
|
||||
foreach (TanmenetItemCo co in coList)
|
||||
{
|
||||
if (!mainImportJsonItemList.Select(x => x.Id).Contains(co.Id))
|
||||
{
|
||||
importItemModelList.Add(new TanmenetImportItemModel
|
||||
{
|
||||
OraSorszam = co.OraSorszam.ToString(),
|
||||
Tema = co.Tema ?? string.Empty,
|
||||
Operation = (int)ImportItemOperationEnum.Delete
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return importItemModelList.OrderBy(x => int.Parse(x.OraSorszam)).ThenByDescending(x => x.OperationText).ToList();
|
||||
}
|
||||
|
||||
private List<TanmenetImportNemImportalhatoItemModel> GetNemImportalhatoItemModelList(List<TanmenetImportItemCo> nemImportalhatoItemList)
|
||||
{
|
||||
var nemImportalhatoItemModelList = new List<TanmenetImportNemImportalhatoItemModel>();
|
||||
foreach (TanmenetImportItemCo nemImportalhatoItem in nemImportalhatoItemList)
|
||||
{
|
||||
nemImportalhatoItemModelList.Add(new TanmenetImportNemImportalhatoItemModel
|
||||
{
|
||||
OraszamImportData = nemImportalhatoItem.OraszamImportData,
|
||||
TemaImportData = nemImportalhatoItem.TemaImportData,
|
||||
|
||||
ErrorList = string.Join(Environment.NewLine, nemImportalhatoItem.ErrorList)
|
||||
});
|
||||
}
|
||||
|
||||
return nemImportalhatoItemModelList.OrderBy(x => x.OraszamImportData).ToList();
|
||||
}
|
||||
|
||||
[NonAction]
|
||||
protected ActionResult Import(string tovabbUrl)
|
||||
{
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
var helper = new TanmenetImportExportHelper(ConnectionTypeExtensions.GetSessionConnectionType());
|
||||
TanmenetImportCo importCo = helper.ImportCo;
|
||||
helper.Import(new { ImportJson = importCo }, importCo.ImportMuvelet, importCo.Tantargyfelosztas.TantargyId, importCo.Tantargyfelosztas.OsztalyCsoportId);
|
||||
|
||||
return Content(Url.Content(tovabbUrl));
|
||||
}
|
||||
|
||||
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
|
||||
}
|
||||
|
||||
#endregion Import
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue