325 lines
12 KiB
C#
325 lines
12 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using Kreta.BusinessLogic.HelperClasses;
|
|
using Kreta.Core;
|
|
using Kreta.Core.ConnectionType;
|
|
using Kreta.Core.Exceptions;
|
|
using Kreta.DataAccess.Interfaces;
|
|
using Kreta.DataAccessManual;
|
|
using Kreta.DataAccessManual.Interfaces;
|
|
using Kreta.DataAccessManual.Util;
|
|
using Kreta.Resources;
|
|
|
|
namespace Kreta.BusinessLogic.Helpers
|
|
{
|
|
public class NemKotottMunkaidoHelper : LogicBase
|
|
{
|
|
public NemKotottMunkaidoHelper(IConnectionType connectionType) : base(connectionType) { }
|
|
|
|
public NemKotottMunkaidoCO GetNemKotottMunkaidoById(int id)
|
|
{
|
|
return Dal.CustomConnection.Run(ConnectionType, helper =>
|
|
{
|
|
var dal = helper.NemKotottMunkaido();
|
|
var entity = dal.GetNemKotottMunkaidoById(id);
|
|
|
|
return ConvertNewCo(entity);
|
|
});
|
|
}
|
|
|
|
public int GetNemKotottMunkaidoId(int oralatogatasId, int tanarId)
|
|
{
|
|
return Dal.CustomConnection.Run(ConnectionType, helper =>
|
|
{
|
|
var dal = helper.NemKotottMunkaido();
|
|
return dal.GetNemKotottMunkaidoId(oralatogatasId, tanarId);
|
|
});
|
|
}
|
|
|
|
public List<DateTime> GetNapokForNemKotottMunkaidoInsert(DateTime startDate, DateTime endDate, DateTime selectedDate, int hetirendId)
|
|
{
|
|
return Dal.CustomConnection.Run(ConnectionType, helper =>
|
|
{
|
|
var dal = helper.NemKotottMunkaido();
|
|
var ds = dal.GetNapokForNemKotottMunkaidoInsert(IntezmenyId, TanevId, startDate, endDate, selectedDate, hetirendId);
|
|
|
|
List<DateTime> list = new List<DateTime>();
|
|
foreach (DataRow item in ds.Tables[0].Rows)
|
|
{
|
|
list.Add(item.Field<DateTime>("Datum"));
|
|
}
|
|
|
|
return list;
|
|
});
|
|
}
|
|
|
|
public List<int> GetNapokForNemKotottMunkaidoDelete(DateTime startDate, DateTime endDate, string groupId)
|
|
{
|
|
return Dal.CustomConnection.Run(ConnectionType, helper =>
|
|
{
|
|
var dal = helper.NemKotottMunkaido();
|
|
var ds = dal.GetNapokForNemKotottMunkaidoDelete(IntezmenyId, TanevId, startDate, endDate, groupId);
|
|
|
|
List<int> list = new List<int>();
|
|
foreach (DataRow item in ds.Tables[0].Rows)
|
|
{
|
|
list.Add(item.Field<int>("Id"));
|
|
}
|
|
|
|
return list;
|
|
});
|
|
}
|
|
|
|
public int Insert(NemKotottMunkaidoCO co)
|
|
{
|
|
return Dal.CustomConnection.Run(ConnectionType, h =>
|
|
{
|
|
var isEnabledNemKotottMunkaidoRogzitese = new TanevrendHelper(new DalHandlerConnectionType(ConnectionType, h)).EnabledNemKotottMunkaidoRogzitese(co.Kezdete);
|
|
|
|
if (!isEnabledNemKotottMunkaidoRogzitese)
|
|
{
|
|
throw new BlException(OrarendResource.NemEngedélyezettNemKotottMunkaidoNaplozasa);
|
|
}
|
|
|
|
var dal = h.NemKotottMunkaido();
|
|
INemKotottMunkaido entity = ConvertNewEntity(co, dal.Get());
|
|
|
|
return dal.Insert(entity);
|
|
});
|
|
}
|
|
|
|
|
|
public void Update(NemKotottMunkaidoCO co)
|
|
{
|
|
Dal.CustomConnection.Run(ConnectionType, h =>
|
|
{
|
|
var isEnabledNemKotottMunkaidoRogzitese = new TanevrendHelper(new DalHandlerConnectionType(ConnectionType, h)).EnabledNemKotottMunkaidoRogzitese(co.Kezdete);
|
|
|
|
if (!isEnabledNemKotottMunkaidoRogzitese)
|
|
{
|
|
throw new BlException(OrarendResource.NemEngedélyezettNemKotottMunkaidoNaplozasa);
|
|
}
|
|
|
|
var dal = h.NemKotottMunkaido();
|
|
if (co.TulajId == FelhasznaloId)
|
|
{
|
|
dal.Update(co.Id.Value, co.Megtartott, co.NaplozottMegjegyzes, co.Kezdete, co.Vege, co.TorvenyKategoriaId);
|
|
}
|
|
else if (co.TulajId != FelhasznaloId)
|
|
{
|
|
dal.Update(co.Id.Value, co.Megtartott, co.NaplozottMegjegyzes);
|
|
}
|
|
});
|
|
}
|
|
|
|
public void UpdateNemKotottMunkaIdoByGroupId(NemKotottMunkaidoCO co, DateTime pIdoszakKezdete, DateTime pIdoszakVege, string pNewGroupId = null)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(pNewGroupId))
|
|
{
|
|
pNewGroupId = co.GroupId;
|
|
}
|
|
|
|
Dal.CustomConnection.Run(ConnectionType, h =>
|
|
{
|
|
var dal = h.NemKotottMunkaido();
|
|
dal.UpdateNemKotottMunkaIdoByGroupId(TanevId, co.GroupId, pIdoszakKezdete, pIdoszakVege, pNewGroupId, co.TorvenyKategoriaId, co.Megjegyzes, FelhasznaloId);
|
|
});
|
|
}
|
|
|
|
public void Delete(int id, bool isAdmin, bool isGlobal = false)
|
|
{
|
|
Dal.CustomConnection.Run(ConnectionType, helper =>
|
|
{
|
|
var dal = helper.NemKotottMunkaido();
|
|
var entity = dal.GetNemKotottMunkaidoById(id);
|
|
|
|
if (isGlobal)
|
|
{
|
|
dal.Delete(id);
|
|
}
|
|
else if (!isAdmin)
|
|
{
|
|
dal.Update(id, megtartott: false);
|
|
}
|
|
else if (isAdmin)
|
|
{
|
|
dal.AdminDelete(id);
|
|
}
|
|
});
|
|
}
|
|
|
|
public void DeleteTanarAltal(int id)
|
|
{
|
|
Dal.CustomConnection.Run(ConnectionType, helper =>
|
|
{
|
|
var dal = helper.NemKotottMunkaido();
|
|
|
|
dal.TanarDelete(id);
|
|
});
|
|
}
|
|
|
|
public List<NevOktLeNemKotottMunkaidoItemCO> GetNevOktLeNemKotottMunkaidoItemCoList(NevOktLeNemKotottMunkaidoSearchCO searchCo)
|
|
{
|
|
return Dal.CustomConnection.Run(ConnectionType, h =>
|
|
{
|
|
var dal = h.NemKotottMunkaido();
|
|
var ds = dal.GetNemKotottMunkaidoData(TanevId, searchCo.FeladatKategoriaId, searchCo.FeladatEllatasiHelyId);
|
|
var result = new List<NevOktLeNemKotottMunkaidoItemCO>();
|
|
foreach (var row in ds.Tables[0].AsEnumerable())
|
|
{
|
|
result.Add(new NevOktLeNemKotottMunkaidoItemCO(row));
|
|
}
|
|
return FilterNevOktLeNemKotottMunkaido(result, searchCo);
|
|
});
|
|
}
|
|
|
|
private INemKotottMunkaido ConvertNewEntity(NemKotottMunkaidoCO co, INemKotottMunkaido nemKotottMunkaido)
|
|
{
|
|
nemKotottMunkaido.GroupId = co.GroupId;
|
|
nemKotottMunkaido.TanarId = co.TanarId;
|
|
nemKotottMunkaido.TulajdonosId = FelhasznaloId;
|
|
nemKotottMunkaido.TevekenysegTipusa = co.TorvenyKategoriaId;
|
|
nemKotottMunkaido.Kezdete = co.Kezdete;
|
|
nemKotottMunkaido.Vege = co.Vege;
|
|
nemKotottMunkaido.Megtartott = co.Megtartott;
|
|
nemKotottMunkaido.Megjegyzes = co.Megjegyzes;
|
|
nemKotottMunkaido.NaplozottMegjegyzes = co.NaplozottMegjegyzes;
|
|
nemKotottMunkaido.Hetirend = co.HetirendId;
|
|
nemKotottMunkaido.AdminAltalTorolt = false;
|
|
nemKotottMunkaido.TanevId = TanevId;
|
|
nemKotottMunkaido.RogzitesDatuma = DateTime.Today;
|
|
|
|
return nemKotottMunkaido;
|
|
}
|
|
|
|
private INemKotottMunkaido ConvertEntity(NemKotottMunkaidoCO co, INemKotottMunkaido nemKotottMunkaido)
|
|
{
|
|
nemKotottMunkaido.ID = co.Id.Value;
|
|
nemKotottMunkaido.GroupId = co.GroupId;
|
|
nemKotottMunkaido.TanarId = co.TanarId;
|
|
nemKotottMunkaido.TulajdonosId = co.TulajId;
|
|
nemKotottMunkaido.TevekenysegTipusa = co.TorvenyKategoriaId;
|
|
nemKotottMunkaido.Kezdete = co.Kezdete;
|
|
nemKotottMunkaido.Vege = co.Vege;
|
|
nemKotottMunkaido.Megtartott = co.Megtartott;
|
|
nemKotottMunkaido.Megjegyzes = co.Megjegyzes;
|
|
nemKotottMunkaido.Hetirend = co.HetirendId;
|
|
|
|
return nemKotottMunkaido;
|
|
}
|
|
|
|
private NemKotottMunkaidoCO ConvertNewCo(INemKotottMunkaido entity)
|
|
{
|
|
var co = new NemKotottMunkaidoCO()
|
|
{
|
|
Id = entity.ID,
|
|
GroupId = entity.GroupId,
|
|
TanarId = entity.TanarId,
|
|
TulajId = entity.TulajdonosId,
|
|
Kezdete = entity.Kezdete,
|
|
Vege = entity.Vege,
|
|
TorvenyKategoriaId = entity.TevekenysegTipusa,
|
|
Megtartott = entity.Megtartott ?? false,
|
|
Megjegyzes = entity.Megjegyzes,
|
|
NaplozottMegjegyzes = entity.NaplozottMegjegyzes,
|
|
HetirendId = entity.Hetirend,
|
|
isReadonly = entity.Fogadoora.Count > 0, //Ha fogadóórához kapcoslódik, akkor csak readonly
|
|
isTanarAltalTorolt = entity.IsTanarAltalTorolt
|
|
};
|
|
|
|
return co;
|
|
}
|
|
|
|
private List<NevOktLeNemKotottMunkaidoItemCO> FilterNevOktLeNemKotottMunkaido(List<NevOktLeNemKotottMunkaidoItemCO> data, NevOktLeNemKotottMunkaidoSearchCO searchCo)
|
|
{
|
|
IEnumerable<NevOktLeNemKotottMunkaidoItemCO> result = data.AsEnumerable();
|
|
|
|
if (searchCo.TanarId.HasValue)
|
|
{
|
|
result = result.Where(x => x.TanarId == searchCo.TanarId.Value);
|
|
}
|
|
|
|
if (searchCo.Kategoria.HasValue)
|
|
{
|
|
result = result.Where(x => x.KategoriaId == searchCo.Kategoria.Value);
|
|
}
|
|
|
|
if (searchCo.DatumTol.HasValue)
|
|
{
|
|
result = result.Where(x => x.Datum >= searchCo.DatumTol.Value.StartOfTheDay());
|
|
}
|
|
|
|
if (searchCo.DatumIg.HasValue)
|
|
{
|
|
result = result.Where(x => x.Datum < searchCo.DatumIg.Value.EndOfTheDay());
|
|
}
|
|
|
|
if (searchCo.KezdeteTol.HasValue)
|
|
{
|
|
result = result.Where(x => x.Kezdete.Value.TimeOfDay >= searchCo.KezdeteTol.Value.TimeOfDay);
|
|
}
|
|
|
|
if (searchCo.KezdeteIg.HasValue)
|
|
{
|
|
result = result.Where(x => x.Kezdete.Value.TimeOfDay < searchCo.KezdeteIg.Value.TimeOfDay);
|
|
}
|
|
|
|
if (searchCo.VegeTol.HasValue)
|
|
{
|
|
result = result.Where(x => x.Vege.Value.TimeOfDay >= searchCo.VegeTol.Value.TimeOfDay);
|
|
}
|
|
|
|
if (searchCo.VegeIg.HasValue)
|
|
{
|
|
result = result.Where(x => x.Vege.Value.TimeOfDay < searchCo.VegeIg.Value.TimeOfDay);
|
|
}
|
|
|
|
if (searchCo.RogzitesDatumaTol.HasValue)
|
|
{
|
|
result = result.Where(x => x.RogzitesDatuma >= searchCo.RogzitesDatumaTol.Value.StartOfTheDay());
|
|
}
|
|
|
|
if (searchCo.RogzitesDatumaIg.HasValue)
|
|
{
|
|
result = result.Where(x => x.RogzitesDatuma < searchCo.RogzitesDatumaIg.Value.EndOfTheDay());
|
|
}
|
|
|
|
if (searchCo.IsToroltTevekenysegek.HasValue)
|
|
{
|
|
result = result.Where(x => x.IsToroltTevekenysegek == searchCo.IsToroltTevekenysegek.ToBool());
|
|
}
|
|
|
|
return result.ToList();
|
|
}
|
|
|
|
public bool HasTanarNemKotottMunkaidoUtkozes(int tanarId, DateTime oraKezdete, DateTime oraVege, int? nemkotottId)
|
|
{
|
|
return Dal.CustomConnection.Run(ConnectionType, h =>
|
|
{
|
|
var dal = h.NemKotottMunkaido();
|
|
var result = dal.HasTanarNemKotottMunkaidoUtkozes(tanarId, oraKezdete, oraVege, nemkotottId);
|
|
|
|
return result;
|
|
});
|
|
}
|
|
|
|
public List<NevOktLeNemKotottMunkaidoItemHelyettesitesCO> GetNemKotottMunkaIdoHelyettesiteshez(DateTime oraKezdete, DateTime oraVege)
|
|
{
|
|
return Dal.CustomConnection.Run(ConnectionType, h =>
|
|
{
|
|
var dal = h.NemKotottMunkaido();
|
|
var dataSet = dal.GetNemKotottMunkaIdoHelyettesiteshez(TanevId, oraKezdete, oraVege);
|
|
|
|
var result = new List<NevOktLeNemKotottMunkaidoItemHelyettesitesCO>();
|
|
foreach (var row in dataSet.Tables[0].AsEnumerable())
|
|
{
|
|
result.Add(new NevOktLeNemKotottMunkaidoItemHelyettesitesCO(row));
|
|
}
|
|
|
|
return result;
|
|
});
|
|
}
|
|
}
|
|
}
|