using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Ease.Core.DataAccess; using Ease.Core.Model; using Ease.Core.Utility; using HRM.BO; namespace HRM.DA.Service.Tax { public class EmpTaxAitService: ServiceTemplate, IEmpTaxAitService { private void MapObject(EmpTaxAit item, DataReader dataReader) { base.SetObjectID(item, dataReader.GetInt32("EmpTaxAitId").Value); item.TaxParamId = dataReader.GetInt32("TaxParamId").Value; item.EmployeeId = dataReader.GetInt32("EmployeeId").Value; item.Name = dataReader.GetString("Name"); item.Remarks = dataReader.GetString("Remarks"); item.Amount = dataReader.GetDouble("Amount").Value; item.CheckedBy = dataReader.GetInt32("CheckedBy"); item.CheckedDate = dataReader.GetDateTime("CheckedDate"); item.TaxEffectDone = (EnumTaxAITInvestment)dataReader.GetInt32("taxeffectDone").Value; item.EntryFrom = (EnumTaxInvestment)dataReader.GetInt32("EntryFrom").Value; item.CreatedBy = dataReader.GetInt32("CreatedBy").Value; item.ModifiedBy = dataReader.GetInt32("ModifiedBy"); item.CreatedDate = dataReader.GetDateTime("CreatedDate").Value; item.ModifiedDate = dataReader.GetDateTime("ModifiedDate"); item.Reason = dataReader.GetString("Reason"); item.ActionDate = dataReader.GetDateTime("ActionDate"); this.SetObjectState(item, Ease.Core.ObjectState.Saved); } protected override T CreateObject(DataReader dataReader) { EmpTaxAit empTaxAit = new EmpTaxAit(); MapObject(empTaxAit, dataReader); return empTaxAit as T; } protected EmpTaxAit CreateObject(DataReader dataReader) { EmpTaxAit empTaxAit = new EmpTaxAit(); MapObject(empTaxAit, dataReader); return empTaxAit; } public EmpTaxAit Get(int id) { EmpTaxAit empTaxAit = new EmpTaxAit(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(EmpTaxAitDA.Get(tc, id)); empTaxAit = this.CreateObject(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 empTaxAit; } public List GetAll() { List items = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(EmpTaxAitDA.GetAll(tc)); items = this.CreateObjects(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 items; } public List GetByEmpId(int empId) { List items = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(EmpTaxAitDA.GetByEmpId(tc, empId)); items = this.CreateObjects(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 items; } public List GetByTaxParamIdForAdmin(int taxParamId, int entryFrom, int taxEffect) { List items = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(EmpTaxAitDA.GetByTaxParamIdForAdmin(tc, taxParamId, entryFrom, taxEffect)); items = this.CreateObjects(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 items; } public List GetByTaxParamIdAndEmpId(int taxParamId, int empId) { List items = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(EmpTaxAitDA.GetByTaxParamIdAndEmpId(tc, taxParamId, empId)); items = this.CreateObjects(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 items; } public int Save(EmpTaxAit item) { int id; TransactionContext tc = null; try { tc = TransactionContext.Begin(); EmpTaxAitDA.Delete(tc, item.TaxParamId, item.EmployeeId); if (item.IsNew) { id = tc.GenerateID("EmpTaxAit", "EmpTaxAitId"); base.SetObjectID(item, id); EmpTaxAitDA.Insert(tc, item); item.AitAttachment.AitID = item.ID; if (item.AitAttachment != null) { if (item.AitAttachment.ID <= 0 && item.AitAttachment.PreviousFileTobase64 != null) { AitAttachmentDA.Insert(item.AitAttachment, item.AitAttachment.ConnectionString); } } } else { id = item.ID; EmpTaxAitDA.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 } return id; } public void Delete(int id) { TransactionContext tc = null; try { tc = TransactionContext.Begin(); EmpTaxAitDA.Delete(tc, id); this.DeleteTaxAttachment(tc, id, EnumTaxAttachment.Ait); 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 DeleteTaxAttachment(TransactionContext tc, int id, EnumTaxAttachment enumTaxAttachment) { try { TaxAttachmentDA.Delete(tc, id, enumTaxAttachment); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public List GetTaxAttachment(int empid, EnumTaxAttachment fileType) { List items = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(TaxAttachmentDA.GetAllAttachmentsByEmpId(tc, empid, fileType)); while (oreader.Read()) { AitAttachment item = new AitAttachment(); item.ID = oreader.GetInt32("TaxAttachmentID").Value; item.ReferenceID = oreader.GetInt32("ReferenceID").Value; item.AitID = oreader.GetInt32("ID").Value; item.FileAsByteArray = oreader.GetLob("FileData"); item.EmployeeID = empid; item.FileType = (EnumTaxAttachment)oreader.GetInt32("fileType").Value; item.OriginalFileName = oreader.GetString("OriginalFileName"); items.Add(item); } oreader.Close(); tc.End(); } catch (Exception e) { #region Handle Exception ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return items; } public AitAttachment GetTaxAttachmentByID(int id, int empid, EnumTaxAttachment fileType) { AitAttachment item = new AitAttachment(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(TaxAttachmentDA.GetAllAttachmentsByID(tc, id, empid, fileType)); while (oreader.Read()) { item.ID = oreader.GetInt32("TaxAttachmentID").Value; item.ReferenceID = oreader.GetInt32("ReferenceID").Value; item.AitID = oreader.GetInt32("ID").Value; item.FileAsByteArray = oreader.GetLob("FileData"); item.EmployeeID = empid; item.FileType = (EnumTaxAttachment)oreader.GetInt32("fileType").Value; item.OriginalFileName = oreader.GetString("OriginalFileName"); } oreader.Close(); tc.End(); } catch (Exception e) { #region Handle Exception ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return item; } public List GetByTaxParamIdEffectForAdmin(int taxParamId, int entryFrom, EnumTaxAITInvestment taxEffectB) { List items = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(EmpTaxAitDA.GetByTaxParamIdBYEffectForAdmin(tc, taxParamId, entryFrom, taxEffectB)); items = this.CreateObjects(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 items; } } }