init
This commit is contained in:
commit
e124a47765
19374 changed files with 9806149 additions and 0 deletions
326
KretaWeb/Areas/Tantargy/ApiControllers/OraTervApiController.cs
Normal file
326
KretaWeb/Areas/Tantargy/ApiControllers/OraTervApiController.cs
Normal file
|
@ -0,0 +1,326 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
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.ComboBox;
|
||||
using Kreta.BusinessLogic.HelperClasses;
|
||||
using Kreta.BusinessLogic.Helpers;
|
||||
using Kreta.BusinessLogic.Security;
|
||||
using Kreta.BusinessLogic.Utils;
|
||||
using Kreta.Core.Exceptions;
|
||||
using Kreta.Enums;
|
||||
using Kreta.Framework.Entities;
|
||||
using Kreta.Framework.Util;
|
||||
using Kreta.Resources;
|
||||
using Kreta.Web.Areas.Tantargy.Models;
|
||||
using Kreta.Web.Helpers;
|
||||
using Kreta.Web.Helpers.Error;
|
||||
using Kreta.Web.Helpers.Grid;
|
||||
using Kreta.Web.Security;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Kreta.Web.Areas.Tantargy.ApiControllers
|
||||
{
|
||||
[ApiRoleClaimsAuthorize(true)]
|
||||
[ApiRolePackageAuthorize(KretaClaimPackages.Adminisztrator.ClaimValue)]
|
||||
public class OraTervApiController : ApiController
|
||||
{
|
||||
/// <summary>
|
||||
/// Visszaadja a Grid result-ot (1 szint)
|
||||
/// </summary>
|
||||
/// <param name="data"></param>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
public DataSourceResult GetOraTervGrid(string data, [ModelBinder(typeof(ModelBinder.DataSourceRequestModelBinder))] DataSourceRequest request)
|
||||
{
|
||||
OraTervSearchModel model = JsonConvert.DeserializeObject<OraTervSearchModel>(data);
|
||||
|
||||
OratervHelper helper = new OratervHelper(ConnectionTypeExtensions.GetSessionConnectionType());
|
||||
helper.GridParameters = Converter.GridParameter(request);
|
||||
OratervCO srcCO = Convert_SearchModel_to_CO(model);
|
||||
|
||||
var oraterv = helper.GetOraTerv(srcCO);
|
||||
return oraterv.ToDataSourceResult();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Visszaadja a Grid result-ot (2 szint)
|
||||
/// </summary>
|
||||
/// <param name="data"></param>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
public DataSourceResult GetOraTervDetailGrid(int oratervId, [ModelBinder(typeof(ModelBinder.DataSourceRequestModelBinder))] DataSourceRequest request)
|
||||
{
|
||||
OraTervModel model = new OraTervModel() { OratervId = oratervId };
|
||||
|
||||
OratervHelper helper = new OratervHelper(ConnectionTypeExtensions.GetSessionConnectionType());
|
||||
helper.GridParameters = Converter.GridParameter(request);
|
||||
OratervCO srcCO = Convert_Model_to_CO(model);
|
||||
|
||||
var oratervTantargy = helper.GetOratervTantargy(srcCO);
|
||||
return oratervTantargy.ToDataSourceResult();
|
||||
}
|
||||
|
||||
public int GetOraTervDetailCount(int oratervId)
|
||||
{
|
||||
OraTervModel model = new OraTervModel() { OratervId = oratervId };
|
||||
|
||||
OratervHelper helper = new OratervHelper(ConnectionTypeExtensions.GetSessionConnectionType());
|
||||
helper.GridParameters = null;
|
||||
OratervCO srcCO = Convert_Model_to_CO(model);
|
||||
return helper.GetOratervTantargy(srcCO).Tables[0].Rows.Count;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Menti egy ÓraTerv adatait
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[ApiValidateAjaxAntiForgeryToken]
|
||||
public HttpResponseMessage SaveOraTervData(OraTervModel model)
|
||||
{
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
if (model.OratervId.HasValue && model.OratervId > 0)
|
||||
{
|
||||
OratervCO co = Convert_Model_to_CO(model);
|
||||
OratervHelper helper = new OratervHelper(ConnectionTypeExtensions.GetSessionConnectionType());
|
||||
var expression = $"OratervId <> {model.OratervId.Value}";
|
||||
//Egyedi Nev validacio
|
||||
if (helper.GetOraTerv(new OratervCO { Nev = co.Nev, IsValidacio = true }).Tables[0].Select(expression).ToList().Any())
|
||||
throw new StatusError(HttpStatusCode.BadRequest, ErrorResource.DuplikaltOraterv);
|
||||
|
||||
helper.UpdateOratervCO(co);
|
||||
}
|
||||
else
|
||||
{
|
||||
OratervCO co = Convert_Model_to_CO(model);
|
||||
OratervHelper helper = new OratervHelper(ConnectionTypeExtensions.GetSessionConnectionType());
|
||||
//Egyedi Nev validacio
|
||||
if (helper.GetOraTerv(new OratervCO { Nev = co.Nev, IsValidacio = true }).Tables[0].Rows.Count > 0)
|
||||
throw new StatusError(HttpStatusCode.BadRequest, ErrorResource.DuplikaltOraterv);
|
||||
|
||||
helper.InsertOratervCO(co);
|
||||
}
|
||||
return new HttpResponseMessage(HttpStatusCode.OK);
|
||||
}
|
||||
|
||||
return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tantárgy insert egy OraTervhez
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[ApiValidateAjaxAntiForgeryToken]
|
||||
public HttpResponseMessage AddOraTervTargy(OraTervTargyModel model)
|
||||
{
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (model.OratervTantargyId.HasValue && model.OratervTantargyId > 0)
|
||||
{
|
||||
OratervTantargyCO co = Convert_Model_to_CO(model);
|
||||
OratervHelper helper = new OratervHelper(ConnectionTypeExtensions.GetSessionConnectionType());
|
||||
helper.UpdateOratervTantargyCO(co, ClaimData.IsActivTanev);
|
||||
}
|
||||
else
|
||||
{
|
||||
OratervTantargyCO co = Convert_Model_to_CO(model);
|
||||
OratervHelper helper = new OratervHelper(ConnectionTypeExtensions.GetSessionConnectionType());
|
||||
helper.InsertOratervTantargyCO(co, ClaimData.IsActivTanev);
|
||||
}
|
||||
return new HttpResponseMessage(HttpStatusCode.OK);
|
||||
}
|
||||
catch (BlException exception)
|
||||
{
|
||||
throw new StatusError(HttpStatusCode.BadRequest, exception.Message);
|
||||
}
|
||||
}
|
||||
|
||||
return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Töröl egy óratervet
|
||||
/// </summary>
|
||||
/// <param name="parameters"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[ApiValidateAjaxAntiForgeryToken]
|
||||
public HttpResponseMessage DeleteOraTerv([FromBody] int oratervID)
|
||||
{
|
||||
if (ClaimData.SelectedTanevID == ClaimData.KovTanevID)
|
||||
{
|
||||
throw new StatusError(HttpStatusCode.BadRequest, ErrorResource.OratervTorleseCsakAzAktualisTanevbenLehetseges);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
OratervHelper helper = new OratervHelper(ConnectionTypeExtensions.GetSessionConnectionType());
|
||||
if (helper.IfModifyOrDeleteOraTerv(oratervID))
|
||||
{
|
||||
helper.DeleteOratervCO(oratervID);
|
||||
return new HttpResponseMessage(HttpStatusCode.OK);
|
||||
}
|
||||
|
||||
throw new StatusError(HttpStatusCode.BadRequest, ErrorResource.TorlesCsakAkkorLehetsegesHaAzOratervhezNincsRogzitveTantargy);
|
||||
|
||||
}
|
||||
catch (EntityDeleteFailedException ex)
|
||||
{
|
||||
var errorMessage = string.Format(ErrorResource.NemTorolhetoKapcsolatMiatt, TantargyResource.Oraterv, ex.ConnectionErrorMessage);
|
||||
|
||||
throw new StatusError(HttpStatusCode.BadRequest, errorMessage);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Töröl egy óraterv tantárgyat
|
||||
/// </summary>
|
||||
/// <param name="parameters"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[ApiValidateAjaxAntiForgeryToken]
|
||||
public HttpResponseMessage DeleteOraTervTantargy([FromBody] int tantargyID)
|
||||
{
|
||||
OratervHelper helper = new OratervHelper(ConnectionTypeExtensions.GetSessionConnectionType());
|
||||
helper.DeleteOratervTantargy(tantargyID);
|
||||
return new HttpResponseMessage(HttpStatusCode.OK);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Törli az összes tantárgyat egy óratervhez
|
||||
/// </summary>
|
||||
/// <param name="parameters"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[ApiValidateAjaxAntiForgeryToken]
|
||||
public HttpResponseMessage DeleteAllOraTervTantargy([FromBody] int id)
|
||||
{
|
||||
OratervHelper helper = new OratervHelper(ConnectionTypeExtensions.GetSessionConnectionType());
|
||||
helper.DeleteAllOratervTantargy(id);
|
||||
return new HttpResponseMessage(HttpStatusCode.OK);
|
||||
}
|
||||
|
||||
#region Helpers
|
||||
|
||||
public class ItemModel
|
||||
{
|
||||
public int Id { set; get; }
|
||||
}
|
||||
|
||||
private OratervCO Convert_Model_to_CO(OraTervModel model)
|
||||
{
|
||||
OratervCO co = new OratervCO()
|
||||
{
|
||||
OratervId = model.OratervId,
|
||||
TantervId = model.TantervId,
|
||||
Evfolyam = model.EvfolyamId ?? 0,
|
||||
Nev = model.Nev
|
||||
};
|
||||
return co;
|
||||
}
|
||||
|
||||
private OratervCO Convert_SearchModel_to_CO(OraTervSearchModel model)
|
||||
{
|
||||
OratervCO co = new OratervCO()
|
||||
{
|
||||
TantervId = model.TantervIdSearch,
|
||||
Evfolyam = model.EvfolyamIdSearch ?? 0,
|
||||
Nev = model.NevSearch
|
||||
};
|
||||
return co;
|
||||
}
|
||||
|
||||
private OratervTantargyCO Convert_Model_to_CO(OraTervTargyModel model)
|
||||
{
|
||||
OratervTantargyCO co = new OratervTantargyCO()
|
||||
{
|
||||
OratervId = model.OratervId,
|
||||
EvesOraszam = model.EvesOraszam.Value,
|
||||
Tantargy = model.TantargyId.Value,
|
||||
OratervTantargyId = model.OratervTantargyId
|
||||
};
|
||||
return co;
|
||||
}
|
||||
|
||||
private OraTervModel Convert_CO_to_Model(OratervCO co)
|
||||
{
|
||||
OraTervModel model = new OraTervModel()
|
||||
{
|
||||
OratervId = co.OratervId,
|
||||
TantervId = co.TantervId,
|
||||
EvfolyamId = co.Evfolyam,
|
||||
Nev = co.Nev
|
||||
};
|
||||
return model;
|
||||
}
|
||||
|
||||
private OraTervTargyModel Convert_TantargyCO_to_Model(OratervTantargyCO co)
|
||||
{
|
||||
OraTervTargyModel model = new OraTervTargyModel()
|
||||
{
|
||||
OratervId = co.OratervId,
|
||||
EvesOraszam = co.EvesOraszam,
|
||||
TantargyId = co.Tantargy
|
||||
};
|
||||
return model;
|
||||
}
|
||||
|
||||
public OraTervModel GetOraTervElem(int id)
|
||||
{
|
||||
OratervCO co;
|
||||
|
||||
var helper = new OratervHelper(ConnectionTypeExtensions.GetActiveSessionConnectionType());
|
||||
co = helper.GetOratervCO(id);
|
||||
|
||||
OraTervModel model = Convert_CO_to_Model(co);
|
||||
return model;
|
||||
}
|
||||
|
||||
public OraTervTargyModel GetOraTervTantargyElem(int id)
|
||||
{
|
||||
OratervTantargyCO co;
|
||||
|
||||
var helper = new OratervHelper(ConnectionTypeExtensions.GetActiveSessionConnectionType());
|
||||
co = helper.GetOratervTantargyCO(id);
|
||||
|
||||
OraTervTargyModel model = Convert_TantargyCO_to_Model(co);
|
||||
return model;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
// NOTE: Kiszervezni -> GetTantervList ComboBoxHelperApi
|
||||
public JsonResult<List<ComboBoxListItem>> GetTantervList([DataSourceRequest] DataSourceRequest request)
|
||||
{
|
||||
var helper = new TantervHelper(ConnectionTypeExtensions.GetSessionConnectionType());
|
||||
|
||||
var dictionary = helper.GetTanterv("");
|
||||
List<ComboBoxListItem> dropdownListItems = new List<ComboBoxListItem>();
|
||||
|
||||
foreach (var item in dictionary)
|
||||
{
|
||||
ComboBoxListItem sli = new ComboBoxListItem() { Text = item.Value, Value = item.Key };
|
||||
dropdownListItems.Add(sli);
|
||||
}
|
||||
return Json(dropdownListItems);
|
||||
}
|
||||
|
||||
public JsonResult<List<ComboBoxListItem>> GetEvfolyamList([DataSourceRequest] DataSourceRequest request)
|
||||
{
|
||||
List<ComboBoxListItem> items = ((int)GeneratedAdatszotarTipusEnum.EvfolyamTipus).GetItemsByType(ClaimData.SelectedTanevID.Value, true).ToComboBoxItemList();
|
||||
|
||||
return Json(items);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue