using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using HRM.BO; using HRM.DA; using Ease.Core.DataAccess; using Ease.Core.Model; using Ease.Core.Utility; namespace HRM.DA { public class DataPermissionService : ServiceTemplate ,IDataPermissionService { public DataPermissionService() { } private void MapObject(DataPermission oDataPermission, DataReader oReader) { base.SetObjectID(oDataPermission, oReader.GetInt32("DataPermissionID").Value); oDataPermission.UserID = (int)oReader.GetInt32("UserID"); oDataPermission.PayrollTypeID = oReader.GetInt32("PayrollTypeID").Value; oDataPermission.PermissionType = (EnumDataPermissionType)oReader.GetInt32("PermissionType").Value; oDataPermission.ReferenceID = oReader.GetInt32("PayrollTypeID").Value; oDataPermission.CreatedBy = oReader.GetInt32("CreatedBy").Value; oDataPermission.CreatedDate = oReader.GetDateTime("CreatedDate").Value; oDataPermission.PermissionStatus = (EnumMenuPermissionStatus)oReader.GetInt32("PermissionStatus").Value; oDataPermission.referenceName = oReader.GetString("referenceName"); this.SetObjectState(oDataPermission, Ease.Core.ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { DataPermission oDataPermission = new DataPermission(); MapObject(oDataPermission, oReader); return oDataPermission as T; } #region Service implementation public List getUsersByUserType(EnumUserType userType) { List items = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(DataPermissionDA.GetUsersByUserType(tc, userType)); 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 void InsertDataPermission(DataPermission item) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); DataPermissionDA.InsertDataPermission(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 bool hasDataPermission(int userid, int payrolltypeid) { TransactionContext tc = null; bool hasPermission =false; try { tc = TransactionContext.Begin(true); hasPermission = DataPermissionDA.hasPermissoin(tc, userid, payrolltypeid); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); #endregion } return hasPermission; } public DataPermission Get(int id) { DataPermission newDataPermission = new DataPermission(); return newDataPermission; } public string GetNextCode() { TransactionContext tc = null; string _code = ""; try { tc = TransactionContext.Begin(); //#### _code = GlobalFunctionService.GetMaxCode(tc, "religion", "codeautogenerate", "Religion", "Code"); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return _code; } public List Get() { List listDataPermission = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(DataPermissionDA.GetDataPermission(tc)); listDataPermission = 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 listDataPermission; } public List Get(int UserID, int PayrollTypeID) { List listDataPermission = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(DataPermissionDA.Get(tc, UserID, PayrollTypeID)); listDataPermission = 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 listDataPermission; } public int Save(DataPermission oDataPermission) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (oDataPermission.IsNew) { int id = tc.GenerateID("DataPermission", "DataPermissionID"); base.SetObjectID(oDataPermission, id); DataPermissionDA.Insert(tc, oDataPermission); } else { DataPermissionDA.Update(tc, oDataPermission); } tc.End(); return oDataPermission.ID; } 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); DataPermissionDA.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 } } #endregion } }