init
This commit is contained in:
@@ -0,0 +1,301 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Web.Http;
|
||||
using System.Web.Http.ModelBinding;
|
||||
using System.Web.Http.Results;
|
||||
using Kendo.Mvc.UI;
|
||||
using Kreta.BusinessLogic.Classes;
|
||||
using Kreta.BusinessLogic.Classes.ComboBox;
|
||||
using Kreta.BusinessLogic.Exceptions;
|
||||
using Kreta.BusinessLogic.HelperClasses;
|
||||
using Kreta.BusinessLogic.Helpers;
|
||||
using Kreta.BusinessLogic.Logic;
|
||||
using Kreta.BusinessLogic.Security;
|
||||
using Kreta.BusinessLogic.Utils;
|
||||
using Kreta.Core;
|
||||
using Kreta.Core.Exceptions;
|
||||
using Kreta.Enums;
|
||||
using Kreta.Enums.ManualEnums;
|
||||
using Kreta.Framework;
|
||||
using Kreta.Framework.Entities;
|
||||
using Kreta.Framework.Util;
|
||||
using Kreta.Resources;
|
||||
using Kreta.Web.Areas.Intezmeny.Logic;
|
||||
using Kreta.Web.Areas.Intezmeny.Models;
|
||||
using Kreta.Web.Helpers;
|
||||
using Kreta.Web.Helpers.Error;
|
||||
using Kreta.Web.Helpers.Grid;
|
||||
using Kreta.Web.Models;
|
||||
using Kreta.Web.Security;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Kreta.Web.Areas.Intezmeny.ApiControllers
|
||||
{
|
||||
[ApiRoleClaimsAuthorize(true)]
|
||||
[ApiRolePackageAuthorize(KretaClaimPackages.Adminisztrator.ClaimValue)]
|
||||
public class TanevRendjeApiController : ApiController
|
||||
{
|
||||
public DataSourceResult GetTanevRendjeGrid(DataSourceRequest request)
|
||||
{
|
||||
var (gridParameter, modelList) = GetGridData(request);
|
||||
|
||||
return modelList.ToDataSourceResult(gridParameter);
|
||||
}
|
||||
|
||||
public HttpResponseMessage GetExport(DataSourceRequest request)
|
||||
{
|
||||
try
|
||||
{
|
||||
var (gridParameter, modelList) = GetGridData(request);
|
||||
|
||||
modelList = modelList.SortingAndPaging(gridParameter.OrderDictionary);
|
||||
|
||||
var simpleExportColumnCos = SimpleExportLogic.GetSimpleExportColumnCos<TanevRendjeGridModel>(TanevRendjeGridModel.TanevRendjeExportAttributeId);
|
||||
|
||||
var memoryStream = SimpleExportLogic.GetExport(TanevResource.TanevRendjeExportSheetName, simpleExportColumnCos, modelList, ClaimData.SelectedTanevID.Value);
|
||||
|
||||
return HttpResponseExtensions.GetFileHttpResponse(memoryStream.ToArray(), TanevResource.TanevRendjeExportFileName);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new StatusError(HttpStatusCode.BadRequest, ErrorResource.HibaTortentAFajlExportalasaKozben) { UnHandledException = ex };
|
||||
}
|
||||
}
|
||||
|
||||
private (GridParameters gridParameter, List<TanevRendjeGridModel> modelList) GetGridData(DataSourceRequest request)
|
||||
{
|
||||
var gridParameter = Converter.GridParameter(request);
|
||||
|
||||
var coList = new TanevrendHelper(ConnectionTypeExtensions.GetSessionConnectionType()).GetTanevRendjeCoList();
|
||||
var modelList = new List<TanevRendjeGridModel>();
|
||||
|
||||
foreach (var co in coList)
|
||||
{
|
||||
var gridModel = new TanevRendjeGridModel(co);
|
||||
modelList.Add(gridModel);
|
||||
}
|
||||
|
||||
return (gridParameter, modelList);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[ApiValidateAjaxAntiForgeryToken]
|
||||
public HttpResponseMessage CheckTanevRendjeBeforeSave(TanevRendjeModel model)
|
||||
{
|
||||
//utólag egy tanítási nap nem tanítási nappá válik
|
||||
if (OrarendHelper.NemTanitasiNapTipusok.Contains(model.NapTipusa.Value))
|
||||
{
|
||||
var naptariNapHelper = new NaptariNapHelper(ConnectionTypeExtensions.GetSessionConnectionType());
|
||||
Dictionary<int, string> tanarok = naptariNapHelper.GetNaplozottOrakTanarai(model.Datum);
|
||||
if (tanarok.Count > 0)
|
||||
{
|
||||
var result = new
|
||||
{
|
||||
NeedConfirm = true,
|
||||
ConfirmMessage = StringResourcesUtil.GetString(4806)
|
||||
//Az alábbi tanárok már naplóztak órát a kiválasztott napon:
|
||||
+ string.Join(", ", tanarok.Values) + ". "
|
||||
+ StringResourcesUtil.GetString(3226)
|
||||
};
|
||||
|
||||
return Request.CreateResponse(HttpStatusCode.OK, result);
|
||||
}
|
||||
}
|
||||
|
||||
return SaveTanevRendje(model);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[ApiValidateAjaxAntiForgeryToken]
|
||||
public HttpResponseMessage SaveTanevRendje(TanevRendjeModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
TanevRendjeLogic.TanevRendjeValidation(ModelState, model);
|
||||
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
TanevRendjeLogic.CheckTanevRendjeUtkozes(model);
|
||||
model = TanevRendjeLogic.SetNapEsHetirend(model);
|
||||
|
||||
var tanevrendHelper = new TanevrendHelper(ConnectionTypeExtensions.GetSessionConnectionType());
|
||||
if (!tanevrendHelper.IsTanoraOrNapirendRogzitheto(model.NapTipusa.Value))
|
||||
{
|
||||
model.UresOrarend = false;
|
||||
model.OrarendiNap = false;
|
||||
}
|
||||
|
||||
var co = new TanevrendCO
|
||||
{
|
||||
ID = model.TanevRendjeId,
|
||||
Tanev = ClaimData.SelectedTanevID.Value,
|
||||
IntezmenyId = ClaimData.IntezmenyId,
|
||||
Datum = model.Datum.Value,
|
||||
Nap = model.Nap,
|
||||
NapTip = model.NapTipusa,
|
||||
Hetirend = model.Hetirend,
|
||||
Megjegyzes = model.Megjegyzes?.Replace("<script>", "").Replace("</script>", ""),
|
||||
OsszesCsop = model.OsszesCsop,
|
||||
CsengetesiRend = model.CsengetesiRend,
|
||||
ElteroOrarendSzerintiTanitasNapDatum = model.ElteroOrarendSzerintiTanitasNapDatum,
|
||||
UresOrarend = model.UresOrarend,
|
||||
OrarendiNap = model.UresOrarend || model.OrarendiNap,
|
||||
IsEgyediNap = TanevRendjeLogic.IsEgyediNap(model)
|
||||
};
|
||||
//co.OrarendiNap = TanevRendjeLogic.IsOrarendiNap(model);
|
||||
|
||||
tanevrendHelper.SaveOrUpdateTanevRendje(co, model.ModifiedOsztalyCsoportList, model.SelectedOsztalyCsoportIdList);
|
||||
|
||||
return new HttpResponseMessage(HttpStatusCode.OK);
|
||||
}
|
||||
|
||||
return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
|
||||
}
|
||||
catch (BlException e)
|
||||
{
|
||||
throw new StatusError(HttpStatusCode.BadRequest, e.Message) { UnHandledException = e.InnerException };
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[ApiValidateAjaxAntiForgeryToken]
|
||||
public HttpResponseMessage DeleteTanevRendje(TanevrendDeleteModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
var helper = new TanevrendHelper(ConnectionTypeExtensions.GetSessionConnectionType());
|
||||
helper.DeleteTanevRendjeByID(model.TanevrendjeId, model.EgyediRogzitesTorles);
|
||||
return new HttpResponseMessage(HttpStatusCode.OK);
|
||||
}
|
||||
catch (CannotBeDeletedException e)
|
||||
{
|
||||
throw new StatusError(HttpStatusCode.BadRequest, e.Message);
|
||||
}
|
||||
catch (EntityDeleteFailedException ex)
|
||||
{
|
||||
var uzenet = string.Format(ErrorResource.TanevrendjeNemTorolhetoKapcsolatMiatt, ex.ConnectionErrorMessage);
|
||||
throw new StatusError(HttpStatusCode.BadRequest, uzenet);
|
||||
}
|
||||
}
|
||||
|
||||
public DataSourceResult GetTanevRendjeOsztalyCsoportGrid(string data, [ModelBinder(typeof(ModelBinder.DataSourceRequestModelBinder))] DataSourceRequest request)
|
||||
{
|
||||
var model = JsonConvert.DeserializeObject<TanevRendjeModel>(data);
|
||||
|
||||
int tanevRendjeId = -1;
|
||||
if (int.TryParse(model.TanevRendjeId?.ToString(), out int resultId))
|
||||
{
|
||||
tanevRendjeId = resultId;
|
||||
}
|
||||
|
||||
var helper = new TanevrendHelper(ConnectionTypeExtensions.GetSessionConnectionType())
|
||||
{
|
||||
GridParameters = Converter.GridParameter(request)
|
||||
};
|
||||
DataSet ds = helper.GetTanevredhezTartozoOsztCsopList(tanevRendjeId, model.FeladatKategoriaId, model.MukodesiHelyId, model.FeladatEllatasiHelyId);
|
||||
|
||||
return ds.ToDataSourceResult();
|
||||
}
|
||||
|
||||
public DataSourceResult GetNaptariHetGrid(string data, [ModelBinder(typeof(ModelBinder.DataSourceRequestModelBinder))] DataSourceRequest request)
|
||||
{
|
||||
var helper = new NaptariHetHelper(ConnectionTypeExtensions.GetSessionConnectionType())
|
||||
{
|
||||
GridParameters = Converter.GridParameter(request)
|
||||
};
|
||||
|
||||
helper.GridParameters.OrderBy = "HetSorszama ASC";
|
||||
|
||||
DataSet ds = helper.GetNaptariHetList();
|
||||
|
||||
var dataList = new List<NaptariHetGridModel>();
|
||||
DataTable dt = ds.Tables[0];
|
||||
|
||||
foreach (DataRow dr in dt.Rows)
|
||||
{
|
||||
var model = new NaptariHetGridModel()
|
||||
{
|
||||
ID = dr["ID"].ToString(),
|
||||
HetSorszama = SDAConvert.ToInt32(dr["HetSorszama"]),
|
||||
HetKezdoNapja = SDAConvert.ToDateTime(dr["HetKezdoNapja"]).Value,
|
||||
HetUtolsoNapja = SDAConvert.ToDateTime(dr["HetUtolsoNapja"]).Value,
|
||||
Hetirend = SDAConvert.ToInt32(dr["Hetirend"]),
|
||||
};
|
||||
|
||||
dataList.Add(model);
|
||||
}
|
||||
|
||||
var dataSourceResult = new DataSourceResult
|
||||
{
|
||||
Data = dataList,
|
||||
Total = Convert.ToInt32(dt.ExtendedProperties["RowCount"])
|
||||
};
|
||||
|
||||
return dataSourceResult;
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[ApiValidateAjaxAntiForgeryToken]
|
||||
public HttpResponseMessage GetHetirendHelyettesitesList(SetHetirendModel model)
|
||||
{
|
||||
WarningValidationModel validationMsg = new WarningValidationModel();
|
||||
|
||||
if (model.ModifiedHetirendList.Count > 0)
|
||||
{
|
||||
var helper = new NaptariHetHelper(ConnectionTypeExtensions.GetSessionConnectionType());
|
||||
var ds = helper.GetHetirendHelyettesitesList(model.ModifiedHetirendList);
|
||||
if (ds.Tables[0].Rows.Count > 0)
|
||||
{
|
||||
foreach (DataRow row in ds.Tables[0].Rows)
|
||||
{
|
||||
validationMsg.Msg += "<br />";
|
||||
validationMsg.Msg += "<strong>" + HelyettesitesResource.Datum + ":</strong> " + row.Field<DateTime>("Datum").ToShortDateString();
|
||||
validationMsg.Msg += " <strong>" + HelyettesitesResource.Helyettesito + ":</strong> " + row.Field<string>("Helyettesito");
|
||||
validationMsg.Msg += " <strong>" + HelyettesitesResource.Helyettesitett + ":</strong> " + row.Field<string>("fHelyettesitett");
|
||||
validationMsg.Msg += " <strong>" + HelyettesitesResource.OsztalyCsoport + ":</strong> " + row.Field<string>("OsztalyCsoport");
|
||||
validationMsg.Msg += " <strong>" + HelyettesitesResource.Tantargy + ":</strong> " + row.Field<string>("Tantargy");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(validationMsg.Msg))
|
||||
{
|
||||
throw new StatusError(CustomHTTPStatusEnum.WarningMegszakitas, string.Empty) { Json = validationMsg };
|
||||
}
|
||||
|
||||
return new HttpResponseMessage(HttpStatusCode.OK);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[ApiValidateAjaxAntiForgeryToken]
|
||||
public HttpResponseMessage SetHetirend(SetHetirendModel model)
|
||||
{
|
||||
if (model.ModifiedHetirendList.Count > 0)
|
||||
{
|
||||
var helper = new NaptariHetHelper(ConnectionTypeExtensions.GetSessionConnectionType());
|
||||
helper.SetHetirend(model.ModifiedHetirendList);
|
||||
}
|
||||
|
||||
return new HttpResponseMessage(HttpStatusCode.OK);
|
||||
}
|
||||
|
||||
public JsonResult<List<ComboBoxListItem>> GetHetirendList([DataSourceRequest] DataSourceRequest request)
|
||||
{
|
||||
IDictionary<string, string> dictionary = FrameworkEnumExtensions.EnumToList((int)GeneratedAdatszotarTipusEnum.HetiRendTipus, ClaimData.SelectedTanevID.Value);
|
||||
|
||||
dictionary["0"] = StringResourcesUtil.GetString(4254) /*Szünet*/;
|
||||
|
||||
return Json(dictionary.ToComboBoxItemList());
|
||||
}
|
||||
|
||||
public bool GetNaptipusIsTanoraOrTanorakivuli(string napTipusId)
|
||||
{
|
||||
var model = new TanevRendjeModel() { NapTipusa = int.Parse(napTipusId) };
|
||||
return TanevRendjeLogic.IsOrarendiNap(model);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user