using System; using System.Data; using System.Linq; using Ease.CoreV35; using Ease.CoreV35.Model; using Ease.CoreV35.DataAccess; using System.Collections.Generic; using Payroll.BO; using Ease.CoreV35.Caching; namespace Payroll.Service { public class UploadEncashAmountService : ServiceTemplate, IUploadEncashAmountService { #region Private functions and declaration Cache _cache = new Cache(typeof(UploadEncashAmount)); public UploadEncashAmountService() { } private void MapObject(UploadEncashAmount oUploadEncashAmount, DataReader oReader) { base.SetObjectID(oUploadEncashAmount, oReader.GetID("UploadEncashAmountID")); oUploadEncashAmount.EmployeeID = ID.FromInteger(oReader.GetInt32("EMPLOYEEID").Value); oUploadEncashAmount.LeaveID = ID.FromInteger(oReader.GetInt32("LeaveID").Value); oUploadEncashAmount.LeaveYear = oReader.GetInt16("LeaveYear").Value; oUploadEncashAmount.Days = oReader.GetInt16("Days").Value; oUploadEncashAmount.BasicSalary = oReader.GetDouble("BasicSalary").Value; this.SetObjectState(oUploadEncashAmount, Ease.CoreV35.ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { UploadEncashAmount oUploadEncashAmount = new UploadEncashAmount(); MapObject(oUploadEncashAmount, oReader); return oUploadEncashAmount as T; } private UploadEncashAmount CreateObject(DataReader oReader) { UploadEncashAmount oUploadEncashAmount = new UploadEncashAmount(); MapObject(oUploadEncashAmount, oReader); return oUploadEncashAmount; } #endregion #region Service implementation public void Save(ObjectsTemplate items) { ObjectsTemplate prevItems = this.Get(); TransactionContext tc = null; try { tc = TransactionContext.Begin(true); foreach (UploadEncashAmount item in items) { UploadEncashAmount oItem = prevItems.Find(delegate(UploadEncashAmount ea) { return ea.EmployeeID == item.EmployeeID && ea.LeaveID == item.LeaveID && ea.LeaveYear == item.LeaveYear; }); if (oItem == null) { int id = tc.GenerateID("UploadEncashAmount", "UploadEncashAmountID"); base.SetObjectID(item, ID.FromInteger(id)); UploadEncashAmountDA.Insert(tc, item); } else { base.SetObjectID(item, oItem.ID); UploadEncashAmountDA.Update(tc, item); } } tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException("Failed to Save Leave Year: " + e.Message, e); #endregion } } #region Delete Service public void Delete(ID id) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); UploadEncashAmountDA.Delete(id.Integer, tc); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new Exception("Failed to Save UploadEncashAmount due to " + e.Message, e); #endregion } } #endregion public ObjectsTemplate Get(ID empID) { #region Cache Header ObjectsTemplate oUploadEncashAmounts = _cache["Get", empID] as ObjectsTemplate; if (oUploadEncashAmounts != null) return oUploadEncashAmounts; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(UploadEncashAmountDA.Get(tc, empID)); oUploadEncashAmounts = 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 } #region Cache Footer _cache.Add(oUploadEncashAmounts, "Get", empID); #endregion return oUploadEncashAmounts; } public ObjectsTemplate Get() { #region Cache Header ObjectsTemplate oUploadEncashAmounts = _cache["Get"] as ObjectsTemplate; if (oUploadEncashAmounts != null) return oUploadEncashAmounts; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(UploadEncashAmountDA.Get(tc)); oUploadEncashAmounts = 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 } #region Cache Footer _cache.Add(oUploadEncashAmounts, "Get"); #endregion return oUploadEncashAmounts; } #endregion } }