init
This commit is contained in:
commit
e124a47765
19374 changed files with 9806149 additions and 0 deletions
265
KretaWeb/Areas/Tantargy/ApiControllers/TantervekApiController.cs
Normal file
265
KretaWeb/Areas/Tantargy/ApiControllers/TantervekApiController.cs
Normal file
|
@ -0,0 +1,265 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Web.Http;
|
||||
using System.Web.Http.ModelBinding;
|
||||
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.Security;
|
||||
using Kreta.BusinessLogic.Utils;
|
||||
using Kreta.Core;
|
||||
using Kreta.Core.Exceptions;
|
||||
using Kreta.Enums;
|
||||
using Kreta.Framework;
|
||||
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 TantervekApiController : ApiController
|
||||
{
|
||||
public DataSourceResult GetTantervekGrid(string data, [ModelBinder(typeof(ModelBinder.DataSourceRequestModelBinder))] DataSourceRequest request)
|
||||
{
|
||||
TantervSearchModel model = JsonConvert.DeserializeObject<TantervSearchModel>(data);
|
||||
|
||||
TantervHelper helper = new TantervHelper(ConnectionTypeExtensions.GetSessionConnectionType());
|
||||
|
||||
helper.GridParameters = Converter.GridParameter(request);
|
||||
var tantervek = helper.TantervKereses(model.TantervNev, model.JellemzoCsopTipID, model.KezdoEvfolyamID, model.VegzoEvfolyamID, model.IsKerettantervreEpul, model.IsKerettantervSrc);
|
||||
return tantervek.ToDataSourceResult();
|
||||
}
|
||||
|
||||
public TantervModel GetTantervProperties(int tantervID)
|
||||
{
|
||||
TantervCO co;
|
||||
|
||||
TantervHelper thelper = new TantervHelper(ConnectionTypeExtensions.GetSessionConnectionType());
|
||||
|
||||
co = thelper.GetCo(tantervID);
|
||||
|
||||
return ConvertCOtoModel(co);
|
||||
}
|
||||
|
||||
public TantervModModel GetTantervPropertiesMod(int tantervID)
|
||||
{
|
||||
TantervHelper thelper = new TantervHelper(ConnectionTypeExtensions.GetSessionConnectionType());
|
||||
|
||||
TantervCO co = thelper.GetCo(tantervID);
|
||||
TantervModModel model = new TantervModModel()
|
||||
{
|
||||
ID = co.ID,
|
||||
Nev = co.Nev,
|
||||
CsoportTipusa = co.CsoportTipusa,
|
||||
Evfolyamtol = co.Evfolyamtol,
|
||||
Evfolyamig = co.Evfolyamig,
|
||||
KerettantervreEpulo = co.KerettantervreEpulo.ToNullableInt(),
|
||||
IsKerettanterv = co.IsKerettanterv.ToNullableInt()
|
||||
};
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
public DataSourceResult GetTantervOSztalyai(string tantervID, [ModelBinder(typeof(ModelBinder.DataSourceRequestModelBinder))] DataSourceRequest request)
|
||||
{
|
||||
var helper = new TantervHelper(ConnectionTypeExtensions.GetSessionConnectionType());
|
||||
|
||||
helper.GridParameters = Converter.GridParameter(request);
|
||||
|
||||
var ds = helper.GetTantervOsztalyai(SDAConvert.ToInt32(tantervID));
|
||||
|
||||
return ds.ToDataSourceResult();
|
||||
}
|
||||
|
||||
public DataSourceResult GetTantervTanuloi(string tantervID, [ModelBinder(typeof(ModelBinder.DataSourceRequestModelBinder))] DataSourceRequest request)
|
||||
{
|
||||
var helper = new TantervHelper(ConnectionTypeExtensions.GetSessionConnectionType());
|
||||
|
||||
helper.GridParameters = Converter.GridParameter(request);
|
||||
|
||||
var ds = helper.GetTantervTanuloi(SDAConvert.ToInt32(tantervID));
|
||||
|
||||
return ds.ToDataSourceResult();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[ApiValidateAjaxAntiForgeryToken]
|
||||
public HttpResponseMessage SaveModifiedOrNewTanterv(TantervModel tmodel)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
TantervCO co = ConvertModelToCO(tmodel);
|
||||
TantervHelper helper = new TantervHelper(ConnectionTypeExtensions.GetSessionConnectionType());
|
||||
|
||||
if (co.ID.HasValue)
|
||||
{
|
||||
helper.Update(co);
|
||||
}
|
||||
else
|
||||
{
|
||||
helper.Insert(co);
|
||||
}
|
||||
|
||||
return new HttpResponseMessage(HttpStatusCode.OK);
|
||||
}
|
||||
|
||||
return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
|
||||
}
|
||||
catch (SDA.DataProvider.SDADataProviderException ex)
|
||||
{
|
||||
if (ex.Error == SDA.DataProvider.SDADataProviderError.UniqueKeyViolation)
|
||||
{
|
||||
string msg = string.Format(StringResourcesUtil.GetString(3554), StringResourcesUtil.GetString(1589 /*Tanterv neve*/));
|
||||
ModelState.AddModelError("Nev", msg);
|
||||
return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
|
||||
}
|
||||
|
||||
throw;
|
||||
|
||||
}
|
||||
catch (CannotBeInsertedException e)
|
||||
{
|
||||
throw new StatusError(HttpStatusCode.BadRequest, e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
public HttpResponseMessage SaveModTanterv(TantervModModel tmodel)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
var co = ConvertModModelToCO(tmodel);
|
||||
var helper = new TantervHelper(ConnectionTypeExtensions.GetSessionConnectionType());
|
||||
|
||||
if (string.IsNullOrWhiteSpace(tmodel.TantervIDArray))
|
||||
{
|
||||
helper.TantervTobbesModify(co);
|
||||
}
|
||||
else
|
||||
{
|
||||
string[] tantervIDArray = tmodel.TantervIDArray.Split(',');
|
||||
foreach (var item in tantervIDArray)
|
||||
{
|
||||
co.ID = int.Parse(item);
|
||||
helper.TantervTobbesModify(co);
|
||||
}
|
||||
}
|
||||
|
||||
return new HttpResponseMessage(HttpStatusCode.OK);
|
||||
}
|
||||
|
||||
return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
|
||||
}
|
||||
catch (CannotBeInsertedException e)
|
||||
{
|
||||
throw new StatusError(HttpStatusCode.BadRequest, e.Message);
|
||||
}
|
||||
catch (BlException e)
|
||||
{
|
||||
throw new StatusError(HttpStatusCode.BadRequest, e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
private TantervTobbesModCO ConvertModModelToCO(TantervModModel model)
|
||||
{
|
||||
return new TantervTobbesModCO()
|
||||
{
|
||||
ID = model.ID,
|
||||
CsoportTipusa = model.CsoportTipusa,
|
||||
Evfolyamig = model.Evfolyamig,
|
||||
Evfolyamtol = model.Evfolyamtol,
|
||||
KerettantervreEpulo = model.KerettantervreEpulo,
|
||||
IsKerettanterv = model.IsKerettanterv
|
||||
};
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[ApiValidateAjaxAntiForgeryToken]
|
||||
public HttpResponseMessage DeleteTanterv([FromBody] int tantervID)
|
||||
{
|
||||
if (ClaimData.SelectedTanevID == ClaimData.KovTanevID)
|
||||
{
|
||||
throw new StatusError(HttpStatusCode.BadRequest, ErrorResource.TantervTorleseCsakAzAktualisTanevbenLehetseges);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
TantervHelper helper = new TantervHelper(ConnectionTypeExtensions.GetSessionConnectionType());
|
||||
|
||||
var ds = helper.GetAktivTantervDataSet();
|
||||
if (ds.Tables[0].Rows.Count == 1)
|
||||
throw new StatusError(HttpStatusCode.BadRequest, ErrorResource.Legalabb1TantervLetezne);
|
||||
|
||||
helper.Delete(tantervID);
|
||||
return new HttpResponseMessage(HttpStatusCode.OK);
|
||||
}
|
||||
catch (BlException exception)
|
||||
{
|
||||
throw new StatusError(HttpStatusCode.BadRequest, exception.Message);
|
||||
}
|
||||
catch (EntityDeleteFailedException ex)
|
||||
{
|
||||
|
||||
var uzenet = string.Format(ErrorResource.NemTorolhetoKapcsolatMiatt, TanuloResource.Tanterv, ex.ConnectionErrorMessage);
|
||||
throw new StatusError(HttpStatusCode.BadRequest, uzenet);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private TantervCO ConvertModelToCO(TantervModel tmodel)
|
||||
{
|
||||
TantervCO co = new TantervCO()
|
||||
{
|
||||
CsoportTipusa = tmodel.CsoportTipusa ?? -1,
|
||||
Evfolyamig = tmodel.Evfolyamig ?? -1,
|
||||
Evfolyamtol = tmodel.Evfolyamtol ?? -1,
|
||||
ID = tmodel.ID,
|
||||
KerettantervreEpulo = tmodel.KerettantervreEpulo,
|
||||
Megjegyzes = tmodel.Megjegyzes,
|
||||
Nev = tmodel.Nev,
|
||||
IsKerettanterv = tmodel.IsKerettanterv
|
||||
};
|
||||
|
||||
return co;
|
||||
}
|
||||
|
||||
private TantervModel ConvertCOtoModel(TantervCO co)
|
||||
{
|
||||
TantervModel model = new TantervModel()
|
||||
{
|
||||
CsoportTipusa = co.CsoportTipusa,
|
||||
Evfolyamig = co.Evfolyamig,
|
||||
Evfolyamtol = co.Evfolyamtol,
|
||||
ID = co.ID,
|
||||
KerettantervreEpulo = co.KerettantervreEpulo,
|
||||
Megjegyzes = co.Megjegyzes,
|
||||
Nev = co.Nev,
|
||||
IsKerettanterv = co.IsKerettanterv
|
||||
};
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
public System.Web.Http.Results.JsonResult<List<ComboBoxListItem>> GetEvfolyamListS([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