using System; using System.Data; using System.Linq; using System.Collections.Generic; using HRM.BO; using HRM.DA; using Ease.Core.Model; using Ease.Core.DataAccess; using Ease.Core.Utility; using Ease.Core; using NPOI.SS.Formula.Functions; namespace HRM.DA { public class LessonContentService : ServiceTemplate, ILessonContentService { public LessonContentService() { } private void MapObject(LessonContent oLessonContent, DataReader oReader) { base.SetObjectID(oLessonContent, oReader.GetInt32("LessonContentID").Value); oLessonContent.LessonID = oReader.GetInt32("LessonID").Value; oLessonContent.ContentTitle = oReader.GetString("ContentTitle"); oLessonContent.ContentType = (EnumContentType)oReader.GetInt32("ContentType").Value; oLessonContent.Description = oReader.GetString("Description"); oLessonContent.ContentUrl = oReader.GetString("ContentUrl"); oLessonContent.Duration = oReader.GetString("Duration"); oLessonContent.IsMendatory = oReader.GetBoolean("IsMendatory", false); oLessonContent.Status = (EnumStatus)oReader.GetInt32("Status").Value; oLessonContent.AccessLevel = (EnumAccessLevel)oReader.GetInt32("AccessLevel").Value; oLessonContent.ContentSource = (EnumContentSource)oReader.GetInt32("ContentSource").Value; oLessonContent.AccessCount = oReader.GetInt32("AccessCount", 0); oLessonContent.CreatedBy = oReader.GetInt32("CreatedBy", 0); oLessonContent.CreatedDate = oReader.GetDateTime("CreationDate").Value; oLessonContent.ModifiedBy = oReader.GetInt32("ModifiedBy", 0); oLessonContent.ModifiedDate = oReader.GetDateTime("ModifiedDate"); this.SetObjectState(oLessonContent, ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { LessonContent oLessonContent = new LessonContent(); MapObject(oLessonContent, oReader); return oLessonContent as T; } protected LessonContent CreateObject(DataReader oReader) { LessonContent oLessonContent = new LessonContent(); MapObject(oLessonContent, oReader); return oLessonContent; } #region Save public int Save(LessonContent oLessonContent) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (oLessonContent.IsNew) { int ID = tc.GenerateID("LMS_LessonContent", "LessonContentID"); base.SetObjectID(oLessonContent, ID); LessonContentDA.Insert(tc, oLessonContent); } else { LessonContentDA.Update(tc, oLessonContent); } tc.End(); return oLessonContent.ID; } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public int Save(TransactionContext tc, LessonContent oLessonContent) { try { if (oLessonContent.IsNew) { int ID = tc.GenerateID("LMS_LessonContent", "LessonContentID"); base.SetObjectID(oLessonContent, ID); LessonContentDA.Insert(tc, oLessonContent); } else { LessonContentDA.Update(tc, oLessonContent); } return oLessonContent.ID; } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } #endregion #region Update Status public void UpdateStatus(LessonContent oLessonContent) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (oLessonContent.IsNew) { LessonContentDA.UpdateStatus(tc, oLessonContent); } tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } #endregion #region Update Access Counts public void UpdateAccessCount(int ID) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); LessonContentDA.UpdateAccessCount(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 #region Delete public void Delete(int ID) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); LessonContentDA.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 #region GET public LessonContent Get(int id) { LessonContent oLessonContent = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(LessonContentDA.Get(tc, id)); if (oreader.Read()) { oLessonContent = this.CreateObject(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 oLessonContent; } public List Get(EnumStatus status) { List oLessonContent = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(LessonContentDA.Get(tc, status)); oLessonContent = 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 oLessonContent; } public List Get(EnumStatus status, int lessonID) { List oLessonContent = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(LessonContentDA.Get(tc, status, lessonID)); oLessonContent = 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 oLessonContent; } public List GetAll() { List oLessonContent = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(LessonContentDA.GetAll(tc)); oLessonContent = 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 oLessonContent; } public List GetByLessonID(int lessonID) { List oLessonContent = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(LessonContentDA.GetByLessonID(tc, lessonID)); oLessonContent = 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 oLessonContent; } public List GetByLessonID(TransactionContext tc, int lessonID) { List oLessonContent = new List(); try { DataReader dr = new DataReader(LessonContentDA.GetByLessonID(tc, lessonID)); oLessonContent = this.CreateObjects(dr); dr.Close(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return oLessonContent; } #endregion } }