EchoTex_Payroll/HRM.DA/Service/Mail/MailSenderErrorListService.cs
2024-10-14 10:01:49 +06:00

352 lines
11 KiB
C#

using System;
using System.Data;
using Ease.Core.Model;
using Ease.Core.DataAccess;
using Ease.Core;
using System.Collections.Generic;
using Ease.Core.Utility;
using HRM.BO;
namespace HRM.DA
{
#region MailSenderErrorList Service
public class MailSenderErrorListService : ServiceTemplate
{
#region Private functions and declaration
#endregion
public MailSenderErrorListService()
{
}
private void MapObject(MailSenderErrorList oMailSenderErrorList, DataReader oReader)
{
base.SetObjectID(oMailSenderErrorList, (oReader.GetInt32("MailSenderErrorListID").Value));
oMailSenderErrorList.BatchNo = oReader.GetInt32("BatchNo", 0);
oMailSenderErrorList.ToEmpID = oReader.GetInt32("ToEmpID", 0);
oMailSenderErrorList.ReceiveTime = oReader.GetDateTime("ReceiveTime").Value;
oMailSenderErrorList.SendTime = oReader.GetDateTime("SendTime").Value;
oMailSenderErrorList.IsSuccessfull = oReader.GetBoolean("IsSuccessfull").Value;
oMailSenderErrorList.Reason = oReader.GetString("Reason");
oMailSenderErrorList.From = oReader.GetString("MailFrom");
oMailSenderErrorList.To = oReader.GetString("MailTo");
oMailSenderErrorList.CC = oReader.GetString("CC");
oMailSenderErrorList.Subject = oReader.GetString("Subject");
oMailSenderErrorList.Body = oReader.GetString("MailBody");
;
oMailSenderErrorList.Attachments = oReader.GetString("Attachments");
this.SetObjectState(oMailSenderErrorList, Ease.Core.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
MailSenderErrorList oMailSenderErrorList = new MailSenderErrorList();
MapObject(oMailSenderErrorList, oReader);
return oMailSenderErrorList as T;
}
protected MailSenderErrorList CreateObject(DataReader oReader)
{
MailSenderErrorList oMailSenderErrorList = new MailSenderErrorList();
MapObject(oMailSenderErrorList, oReader);
return oMailSenderErrorList;
}
#region Service implementation
public MailSenderErrorList Get(int id)
{
MailSenderErrorList oMailSenderErrorList = new MailSenderErrorList();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(MailSenderErrorListDA.Get(tc, id));
if (oreader.Read())
{
oMailSenderErrorList = this.CreateObject<MailSenderErrorList>(oreader);
}
oreader.Close();
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return oMailSenderErrorList;
}
public List<MailSenderErrorList> Get()
{
List<MailSenderErrorList> MailSenderErrorLists = new List<MailSenderErrorList>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(MailSenderErrorListDA.Get(tc));
MailSenderErrorLists = this.CreateObjects<MailSenderErrorList>(dr);
dr.Close();
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return MailSenderErrorLists;
}
public int Save(MailSenderErrorList oMailSenderErrorList)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oMailSenderErrorList.IsNew)
{
int id = tc.GenerateID("MailSenderErrorList", "MailSenderErrorListID");
base.SetObjectID(oMailSenderErrorList, (id));
MailSenderErrorListDA.Insert(tc, oMailSenderErrorList);
tc.End();
}
else
MailSenderErrorListDA.Update(tc, oMailSenderErrorList);
tc.End();
return oMailSenderErrorList.ID;
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public void Save(List<MailSenderErrorList> oMailSenderErrorLists)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
int id = tc.GenerateID("MailSenderErrorList", "MailSenderErrorListID");
foreach (MailSenderErrorList item in oMailSenderErrorLists)
{
if (item.IsNew)
{
base.SetObjectID(item, (id));
MailSenderErrorListDA.Insert(tc, item);
id++;
}
else
{
MailSenderErrorListDA.Update(tc, item);
}
}
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public void Delete(int id)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
MailSenderErrorListDA.Delete(tc, id);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public void DeleteByBatchNo(int batchNo)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
MailSenderErrorListDA.DeleteByBatchNo(tc, batchNo);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public int GetNewBatchNo()
{
TransactionContext tc = null;
int id;
try
{
tc = TransactionContext.Begin();
id = tc.GenerateID("MailSenderErrorList", "BatchNo");
}
catch (Exception exception)
{
throw exception;
}
return (id);
}
public DataTable GetMailHistory(bool status, EnumSchedularType Type, DateTime fromDate, DateTime toDate)
{
DataTable dataTable = new DataTable();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
dataTable = MailSenderErrorListDA.GetMailHistory(tc, status, Type, fromDate, toDate);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return dataTable;
}
public DataTable GetBatchNoWiseErrorList()
{
DataTable dataTable = new DataTable();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
dataTable = MailSenderErrorListDA.GetBatchNoWiseErrorList(tc);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return dataTable;
}
public List<MailSenderErrorList> GetErrorListByBatchNo(int batchNo)
{
List<MailSenderErrorList> MailSenderErrorLists = new List<MailSenderErrorList>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(MailSenderErrorListDA.GetByBatch(tc, batchNo));
MailSenderErrorLists = this.CreateObjects<MailSenderErrorList>(dr);
dr.Close();
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return MailSenderErrorLists;
}
public void UpdateSendStatus(int nID, bool bStatus)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
MailSenderErrorListDA.UpdateSendStatus(tc, nID, bStatus);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
#endregion
}
#endregion
}