init
This commit is contained in:
commit
e124a47765
19374 changed files with 9806149 additions and 0 deletions
159
Kreta.BusinessLogic/Helpers/DualisSzerzodesHelper.cs
Normal file
159
Kreta.BusinessLogic/Helpers/DualisSzerzodesHelper.cs
Normal file
|
@ -0,0 +1,159 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.IO;
|
||||
using System.Web;
|
||||
using Kreta.BusinessLogic.HelperClasses;
|
||||
using Kreta.BusinessLogic.Interfaces;
|
||||
using Kreta.Client.FileService.Request;
|
||||
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.Enums.ManualEnums;
|
||||
using Kreta.Resources;
|
||||
|
||||
namespace Kreta.BusinessLogic.Helpers
|
||||
{
|
||||
public class DualisSzerzodesHelper : LogicBase
|
||||
{
|
||||
#region Fields
|
||||
|
||||
private readonly IFileServiceHelper fileServiceHelper;
|
||||
|
||||
#endregion Fields
|
||||
|
||||
#region Constructors
|
||||
|
||||
public DualisSzerzodesHelper(IConnectionType connectionType, IFileServiceHelper fileServiceHelper) : base(connectionType)
|
||||
{
|
||||
this.fileServiceHelper = fileServiceHelper ?? throw new ArgumentNullException(nameof(fileServiceHelper));
|
||||
}
|
||||
|
||||
public DualisSzerzodesHelper(IConnectionType connectionType) : base(connectionType) { }
|
||||
|
||||
#endregion Constructors
|
||||
|
||||
#region DualisSzerzodesFileService Functions
|
||||
|
||||
public DataSet GetTanarDualisSzerzodesek()
|
||||
{
|
||||
return Dal.CustomConnection.Run(ConnectionType, h =>
|
||||
{
|
||||
var dal = h.DualisSzerzodesFileDal(GridParameters);
|
||||
return dal.GetTanarDualisSzerzodesek(FelhasznaloId, TanevId);
|
||||
});
|
||||
}
|
||||
|
||||
public DataSet GetDualisSzerzodesek(DualisSzerzodesSearchCo searchCo)
|
||||
{
|
||||
return Dal.CustomConnection.Run(ConnectionType, h =>
|
||||
{
|
||||
var dal = h.DualisSzerzodesFileDal(GridParameters);
|
||||
return dal.GetDualisSzerzodesek(searchCo.ConvertToPCO(), TanevId);
|
||||
});
|
||||
}
|
||||
|
||||
public List<DualisSzerzodesCo> GetDualisSzerzodesekListajaCoList(DualisSzerzodesSearchCo searchCo)
|
||||
{
|
||||
DataSet dataSet = GetDualisSzerzodesek(searchCo);
|
||||
|
||||
var result = new List<DualisSzerzodesCo>();
|
||||
foreach (DataRow dataRow in dataSet.Tables[0].Rows)
|
||||
{
|
||||
var item = new DualisSzerzodesCo(dataRow);
|
||||
result.Add(item);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public void SetFelhasznaloAltalTorolt(int id)
|
||||
{
|
||||
Dal.CustomConnection.Run(ConnectionType, dalHandler =>
|
||||
{
|
||||
SetFelhasznaloAltalTorolt(dalHandler, id, true);
|
||||
});
|
||||
}
|
||||
|
||||
public (string Name, byte[] Data) GetFileData(int id)
|
||||
{
|
||||
IFile file = Dal.CustomConnection.Run(ConnectionType, dalHandler => dalHandler.FileDAL().Get(id));
|
||||
var fileName = string.Concat(file.FileNev.TrimEnd('.'), '.', file.Extension.TrimStart('.'));
|
||||
var fileContent = fileServiceHelper.GetFile(IntezmenyAzonosito, new GetUrlRequest(file.Utvonal, file.FileGuid.Value, fileName));
|
||||
byte[] data = Convert.FromBase64String(fileContent.Tartalom);
|
||||
return (fileName, data);
|
||||
}
|
||||
|
||||
public DualisSzerzodesCo Upload(HttpPostedFileBase postedFile, Guid globalIntezmenyId, int tanuloId)
|
||||
{
|
||||
string fileName = postedFile.FileName;
|
||||
string contentType = postedFile.ContentType;
|
||||
int contentLength = postedFile.ContentLength;
|
||||
try
|
||||
{
|
||||
var ms = new MemoryStream(contentLength);
|
||||
postedFile.InputStream.CopyTo(ms);
|
||||
byte[] content = ms.ToArray();
|
||||
ms.Dispose();
|
||||
return Dal.CustomConnection.Run(ConnectionType, h =>
|
||||
{
|
||||
OsszesTorlese(tanuloId, h);
|
||||
|
||||
IDualisSzerzodesFileDal dualisSzerzodesFileDal = h.DualisSzerzodesFileDal();
|
||||
IDualisSzerzodesFile dualisSzerzodesFile = dualisSzerzodesFileDal.Get();
|
||||
string path = $"DualisSzerzodes/{globalIntezmenyId}/{TanevId}/{FelhasznaloId}/{tanuloId}";
|
||||
var newFileId = new FileHelper(new DalHandlerConnectionType(ConnectionType, h), fileServiceHelper).UploadFile(fileName, content, contentType, path);
|
||||
dualisSzerzodesFile.FileId = newFileId.Value;
|
||||
dualisSzerzodesFile.TanuloId = tanuloId;
|
||||
dualisSzerzodesFile.IntezmenyId = IntezmenyId;
|
||||
dualisSzerzodesFile.TanevId = TanevId;
|
||||
IFelhasznalo tanulo = h.Felhasznalo().Get(tanuloId);
|
||||
dualisSzerzodesFileDal.Insert(dualisSzerzodesFile);
|
||||
return ConvertToCo(tanuloId, dualisSzerzodesFile, tanulo);
|
||||
});
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw new BlException(ErrorResource.FajlFeltolteseSikertelen);
|
||||
}
|
||||
}
|
||||
|
||||
private void OsszesTorlese(int tanuloId, IDalHandler dalHandler)
|
||||
{
|
||||
List<int> regiDualisSzerzodesFileIdList = dalHandler.DualisSzerzodesFileDal().GetDualisSzerzodesId(IntezmenyId, TanevId, FelhasznaloId, tanuloId);
|
||||
foreach (var item in regiDualisSzerzodesFileIdList)
|
||||
{
|
||||
SetFelhasznaloAltalTorolt(dalHandler, item, true);
|
||||
}
|
||||
}
|
||||
|
||||
private void SetFelhasznaloAltalTorolt(IDalHandler dalHandler, int id, bool withFileServiceDelete)
|
||||
{
|
||||
IDualisSzerzodesFile dualisSzerzodesFile = dalHandler.DualisSzerzodesFileDal().Get(id);
|
||||
dualisSzerzodesFile.IsAlkalmazottAltalTorolt = true;
|
||||
dalHandler.DualisSzerzodesFileDal().Update(dualisSzerzodesFile);
|
||||
}
|
||||
|
||||
private DualisSzerzodesCo ConvertToCo(int tanuloId, IDualisSzerzodesFile dualisSzerzodesFile, IFelhasznalo tanulo)
|
||||
{
|
||||
bool hasFile = dualisSzerzodesFile.File != null;
|
||||
return new DualisSzerzodesCo
|
||||
{
|
||||
TanuloId = tanuloId,
|
||||
FeltoltoId = FelhasznaloId,
|
||||
SzerzodesFileId = dualisSzerzodesFile.ID,
|
||||
FileId = hasFile ? dualisSzerzodesFile.File.ID : (int?)default,
|
||||
Statusz = hasFile ? FileStatuszEnum.Feltoltve : FileStatuszEnum.NincsFeltoltve,
|
||||
FileNev = hasFile ? string.Format("{0}.{1}", dualisSzerzodesFile.File.FileNev, dualisSzerzodesFile.File.Extension) : string.Empty,
|
||||
FeltoltesDatuma = hasFile ? dualisSzerzodesFile.File.FeltoltesDatum : (DateTime?)default,
|
||||
TanuloNev = tanulo.NyomtatasiNev
|
||||
};
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue