/// <summary>
        /// Get with transaction
        /// </summary>
        public PM_ALT_NOTI_GROUP Get(object entityId, DbTransaction transaction)
        {
            ArgumentValidator.CheckForNullArgument(entityId, "entityId");
            ArgumentValidator.CheckForNullArgument(transaction, "transaction");

            PM_ALT_NOTI_GROUP PM_ALT_NOTI_GROUPEntity = null;

            try
            {
                Database  db        = GetDatabaseInstance();
                DbCommand dbCommand = db.GetSqlStringCommand(PM_ALT_NOTI_GROUPDAO.SqlGet);

                db.AddInParameter(dbCommand, "@NotiGroupID", DbType.Guid, entityId);
                using (IDataReader dataReader = db.ExecuteReader(dbCommand, transaction))
                {
                    if (dataReader.Read())
                    {
                        PM_ALT_NOTI_GROUPEntity = ReadEntity(dataReader);
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionPolicy.HandleException(ex, ExceptionPolicy.DataAccessDefaultPolicy);
            }

            return(PM_ALT_NOTI_GROUPEntity);
        }
        private void UpdateAll(PM_ALT_NOTI_GROUP entity, DbTransaction transaction)
        {
            ArgumentValidator.CheckForNullArgument(entity, "entity");
            ArgumentValidator.CheckForNullArgument(transaction, "transaction");

            PersistentPM_ALT_NOTI_GROUP PM_ALT_NOTI_GROUPEntity = entity as PersistentPM_ALT_NOTI_GROUP;

            try
            {
                Database  db        = GetDatabaseInstance();
                DbCommand dbCommand = db.GetSqlStringCommand(PM_ALT_NOTI_GROUPDAO.SqlUpdate);

                db.AddInParameter(dbCommand, "@NotiGroupID", DbType.Guid, PM_ALT_NOTI_GROUPEntity.NotiGroupID);
                db.AddInParameter(dbCommand, "@GroupName", DbType.String, PM_ALT_NOTI_GROUPEntity.GroupName);
                db.AddInParameter(dbCommand, "@GroupDesc", DbType.String, PM_ALT_NOTI_GROUPEntity.GroupDesc);
                db.AddInParameter(dbCommand, "@NotiEmail", DbType.Boolean, PM_ALT_NOTI_GROUPEntity.NotiEmail);
                db.AddInParameter(dbCommand, "@NotiSMS", DbType.Boolean, PM_ALT_NOTI_GROUPEntity.NotiSMS);
                db.AddInParameter(dbCommand, "@RowDeleted", DbType.Boolean, PM_ALT_NOTI_GROUPEntity.RowDeleted);
                db.AddInParameter(dbCommand, "@CreatedBy", DbType.String, PM_ALT_NOTI_GROUPEntity.CreatedBy);
                db.AddInParameter(dbCommand, "@CreatedOn", DbType.DateTime, PM_ALT_NOTI_GROUPEntity.CreatedOn);
                db.AddInParameter(dbCommand, "@ModifiedBy", DbType.String, PM_ALT_NOTI_GROUPEntity.ModifiedBy);
                db.AddInParameter(dbCommand, "@ModifiedOn", DbType.DateTime, PM_ALT_NOTI_GROUPEntity.ModifiedOn);
                int result = db.ExecuteNonQuery(dbCommand, transaction);

                if (result == 0)
                {
                    throw new EntityNotFoundException();
                }
            }
            catch (Exception ex)
            {
                ExceptionPolicy.HandleException(ex, ExceptionPolicy.DataAccessDefaultPolicy);
            }
        }
        /// <summary>
        /// Insert
        /// </summary>
        public PM_ALT_NOTI_GROUP Insert(PM_ALT_NOTI_GROUP entity)
        {
            ArgumentValidator.CheckForNullArgument(entity, "entity");
            PersistentPM_ALT_NOTI_GROUP PM_ALT_NOTI_GROUPEntity = entity as PersistentPM_ALT_NOTI_GROUP;

            try
            {
                Database  db        = GetDatabaseInstance();
                DbCommand dbCommand = db.GetSqlStringCommand(PM_ALT_NOTI_GROUPDAO.SqlInsert);

                db.AddInParameter(dbCommand, "@NotiGroupID", DbType.Guid, PM_ALT_NOTI_GROUPEntity.NotiGroupID);
                db.AddInParameter(dbCommand, "@GroupName", DbType.String, PM_ALT_NOTI_GROUPEntity.GroupName);
                db.AddInParameter(dbCommand, "@GroupDesc", DbType.String, PM_ALT_NOTI_GROUPEntity.GroupDesc);
                db.AddInParameter(dbCommand, "@NotiEmail", DbType.Boolean, PM_ALT_NOTI_GROUPEntity.NotiEmail);
                db.AddInParameter(dbCommand, "@NotiSMS", DbType.Boolean, PM_ALT_NOTI_GROUPEntity.NotiSMS);
                db.AddInParameter(dbCommand, "@RowDeleted", DbType.Boolean, PM_ALT_NOTI_GROUPEntity.RowDeleted);
                db.AddInParameter(dbCommand, "@CreatedBy", DbType.String, PM_ALT_NOTI_GROUPEntity.CreatedBy);
                db.AddInParameter(dbCommand, "@CreatedOn", DbType.DateTime, PM_ALT_NOTI_GROUPEntity.CreatedOn);
                db.AddInParameter(dbCommand, "@ModifiedBy", DbType.String, PM_ALT_NOTI_GROUPEntity.ModifiedBy);
                db.AddInParameter(dbCommand, "@ModifiedOn", DbType.DateTime, PM_ALT_NOTI_GROUPEntity.ModifiedOn);

                int result = db.ExecuteNonQuery(dbCommand);
            }
            catch (Exception ex)
            {
                ExceptionPolicy.HandleException(ex, ExceptionPolicy.DataAccessDefaultPolicy);
            }

            return(PM_ALT_NOTI_GROUPEntity as PM_ALT_NOTI_GROUP);
        }
 public void Update(PM_ALT_NOTI_GROUP entity, bool updateAll, DbTransaction transaction)
 {
     if (!updateAll)
     {
         UpdateSome(entity, transaction);
     }
     else
     {
         UpdateAll(entity, transaction);
     }
 }
 public void Update(PM_ALT_NOTI_GROUP entity, bool updateAll)
 {
     if (!updateAll)
     {
         UpdateSome(entity);
     }
     else
     {
         UpdateAll(entity);
     }
 }
        public void UpdateSome(PM_ALT_NOTI_GROUP entity)
        {
            try
            {
                ArgumentValidator.CheckForNullArgument(entity, "PM_ALT_NOTI_GROUP Entity");

                _PM_ALT_NOTI_GROUPDAO.Update(entity, false);
            }
            catch (Exception ex)
            {
                ExceptionPolicy.HandleException(ex, ExceptionPolicy.BusinessLogicDefaultPolicy);
            }
        }
        public void Delete(PM_ALT_NOTI_GROUP entity)
        {
            try
            {
                ArgumentValidator.CheckForNullArgument(entity, "PM_ALT_NOTI_GROUP Entity");

                _PM_ALT_NOTI_GROUPDAO.Delete(entity.NotiGroupID);
            }
            catch (Exception ex)
            {
                ExceptionPolicy.HandleException(ex, ExceptionPolicy.BusinessLogicDefaultPolicy);
            }
        }
        //
        #region base interface impl

        public PM_ALT_NOTI_GROUP Insert(PM_ALT_NOTI_GROUP entity)
        {
            PM_ALT_NOTI_GROUP newEntity = null;

            try
            {
                ArgumentValidator.CheckForNullArgument(entity, "PM_ALT_NOTI_GROUP Entity");

                newEntity = _PM_ALT_NOTI_GROUPDAO.Insert(entity);
            }
            catch (Exception ex)
            {
                ExceptionPolicy.HandleException(ex, ExceptionPolicy.BusinessLogicDefaultPolicy);
            }

            return(newEntity);
        }
        public PM_ALT_NOTI_GROUP GetEntity(Guid entityGuid)
        {
            PM_ALT_NOTI_GROUP entity = null;

            try
            {
                ArgumentValidator.CheckForNullArgument(entityGuid, "PM_ALT_NOTI_GROUP Guid");

                entity = _PM_ALT_NOTI_GROUPDAO.Get(entityGuid);
            }
            catch (Exception ex)
            {
                ExceptionPolicy.HandleException(ex, ExceptionPolicy.BusinessLogicDefaultPolicy);
            }

            return(entity);
        }
        public void Restore(PM_ALT_NOTI_GROUP entity, out string returnMessage)
        {
            returnMessage = string.Empty;
            //
            try
            {
                DateTime?curUTCTime = UtilDAO.GetDatabaseUtcDatetime();
                //
                if (entity == null)
                {
                    returnMessage = "Input parameter [NOTI_GROUP entity] can not be null.";
                    return;
                }
                if (!entity.NotiGroupID.HasValue)
                {
                    returnMessage = "[GROUP ID] can not be null.";
                    return;
                }
                if (string.IsNullOrEmpty(entity.GroupName))
                {
                    returnMessage = "[GROUP NAME] can not be empty.";
                    return;
                }
                //
                SSIdentity identity = SSAuthentication.CurrentIdentity as SSIdentity;
                if (identity == null)
                {
                    returnMessage = "[Authentication.Identity] is required.";
                    return;
                }
                //
                entity.ModifiedBy = identity.Name;
                entity.ModifiedOn = curUTCTime;
                entity.RowDeleted = false;

                this.UpdateSome(entity);
            }
            catch (Exception ex)
            {
                returnMessage = ex.Message;
                return;
            }
        }
        private static PM_ALT_NOTI_GROUP ReadEntity(IDataReader dataReader)
        {
            PM_ALT_NOTI_GROUP PM_ALT_NOTI_GROUPEntity = new PM_ALT_NOTI_GROUP();
            object            value;


            value = dataReader["NotiGroupID"];
            if (value != DBNull.Value)
            {
                PM_ALT_NOTI_GROUPEntity.NotiGroupID = (Guid?)value;
            }

            value = dataReader["GroupName"];
            if (value != DBNull.Value)
            {
                PM_ALT_NOTI_GROUPEntity.GroupName = (String)value;
            }

            value = dataReader["GroupDesc"];
            if (value != DBNull.Value)
            {
                PM_ALT_NOTI_GROUPEntity.GroupDesc = (String)value;
            }

            value = dataReader["NotiEmail"];
            if (value != DBNull.Value)
            {
                PM_ALT_NOTI_GROUPEntity.NotiEmail = (Boolean?)value;
            }

            value = dataReader["NotiSMS"];
            if (value != DBNull.Value)
            {
                PM_ALT_NOTI_GROUPEntity.NotiSMS = (Boolean?)value;
            }

            value = dataReader["RowDeleted"];
            if (value != DBNull.Value)
            {
                PM_ALT_NOTI_GROUPEntity.RowDeleted = (Boolean?)value;
            }

            value = dataReader["CreatedBy"];
            if (value != DBNull.Value)
            {
                PM_ALT_NOTI_GROUPEntity.CreatedBy = (String)value;
            }

            value = dataReader["CreatedOn"];
            if (value != DBNull.Value)
            {
                PM_ALT_NOTI_GROUPEntity.CreatedOn = (DateTime?)value;
            }

            value = dataReader["ModifiedBy"];
            if (value != DBNull.Value)
            {
                PM_ALT_NOTI_GROUPEntity.ModifiedBy = (String)value;
            }

            value = dataReader["ModifiedOn"];
            if (value != DBNull.Value)
            {
                PM_ALT_NOTI_GROUPEntity.ModifiedOn = (DateTime?)value;
            }

            return(PM_ALT_NOTI_GROUPEntity);
        }
        private void UpdateSome(PM_ALT_NOTI_GROUP entity, DbTransaction transaction)
        {
            ArgumentValidator.CheckForNullArgument(entity, "entity");
            ArgumentValidator.CheckForNullArgument(transaction, "transaction");

            PersistentPM_ALT_NOTI_GROUP PM_ALT_NOTI_GROUPEntity = entity as PersistentPM_ALT_NOTI_GROUP;

            StringBuilder sqlUpdateSome = new StringBuilder();

            sqlUpdateSome.Append("UPDATE dbo.PM_ALT_NOTI_GROUP SET ");

            PropertyInfo[] propertyInfos        = PM_ALT_NOTI_GROUPEntity.GetType().GetProperties();
            Hashtable      propertyValues       = new System.Collections.Hashtable();
            int            columnCountForUpdate = 0;

            foreach (PropertyInfo propertyInfo in propertyInfos)
            {
                if (EntityMapping.ContainsProperty(propertyInfo.Name))
                {
                    object     propertyValue = propertyInfo.GetValue(PM_ALT_NOTI_GROUPEntity, null);
                    ORProperty property      = EntityMapping[propertyInfo.Name];
                    if (!property.IsPrimaryKey)
                    {
                        if (!PM_ALT_NOTI_GROUPEntity.IsDefaultValue(propertyInfo.Name))
                        {
                            propertyValues[propertyInfo.Name] = propertyValue;

                            sqlUpdateSome.Append(" " + property.ColumnName + " = @" + property.ColumnName + ",");
                            columnCountForUpdate++;
                        }
                    }
                    else
                    {
                        propertyValues[propertyInfo.Name] = propertyValue;
                    }
                }
            }
            if (columnCountForUpdate == 0)
            {
                return;
            }

            sqlUpdateSome.Remove(sqlUpdateSome.Length - 1, 1);
            sqlUpdateSome.Append(" WHERE 1 = 1 ");
            sqlUpdateSome.Append(" AND NotiGroupID = @NotiGroupID ");

            try
            {
                Database  db        = GetDatabaseInstance();
                DbCommand dbCommand = db.GetSqlStringCommand(sqlUpdateSome.ToString());

                foreach (DictionaryEntry de in propertyValues)
                {
                    ORProperty property = EntityMapping[de.Key.ToString()];
                    db.AddInParameter(dbCommand, "@" + property.ColumnName, property.DatabaseType, de.Value);
                }

                int result = db.ExecuteNonQuery(dbCommand, transaction);

                if (result == 0)
                {
                    throw new EntityNotFoundException();
                }
            }
            catch (Exception ex)
            {
                ExceptionPolicy.HandleException(ex, ExceptionPolicy.DataAccessDefaultPolicy);
            }
        }
        /// <summary>
        /// Update with transaction
        /// </summary>

        public void Update(PM_ALT_NOTI_GROUP entity, DbTransaction transaction)
        {
            Update(entity, true, transaction);
        }
        /// <summary>
        /// Update
        /// </summary>

        public void Update(PM_ALT_NOTI_GROUP entity)
        {
            Update(entity, true);
        }
 //
 public void Save(PM_ALT_NOTI_GROUP entity, IList <PM_ALT_NOTI_GROUP_DETAIL> groupDtls, NotiGroupSaveOptions saveOptions, out string returnMessage)
 {
     returnMessage = string.Empty;
     //
     try
     {
         DateTime?curUTCTime = UtilDAO.GetDatabaseUtcDatetime();
         //
         #region check
         if (saveOptions == null)
         {
             returnMessage = "Input parameter [NotiGroupSaveOptions saveOptions] can not be null.";
             return;
         }
         //
         if (entity == null)
         {
             returnMessage = "Input parameter [NOTI_GROUP entity] can not be null.";
             return;
         }
         if (saveOptions.IsChangeGroupDtl)
         {
             if (groupDtls == null)
             {
                 returnMessage = "Input parameter [IList<NOTI_GROUP_DETAIL> grpDtlList] can not be null.";
                 return;
             }
         }
         //
         #region check security
         SSIdentity identity = SSAuthentication.CurrentIdentity as SSIdentity;
         if (identity == null)
         {
             returnMessage = "[Authentication.Identity] is required.";
             return;
         }
         #endregion
         //
         #region check group
         if (string.IsNullOrEmpty(entity.GroupName))
         {
             returnMessage = "[entity.GroupName] is required.";
             return;
         }
         //
         if (!entity.NotiGroupID.HasValue)
         {
             entity.NotiGroupID = Guid.NewGuid();
             entity.CreatedBy   = identity.Name;
             entity.CreatedOn   = curUTCTime;
         }
         else
         {
             entity.ModifiedBy = identity.Name;
             entity.ModifiedOn = curUTCTime;
         }
         //
         if (string.IsNullOrEmpty(entity.CreatedBy))
         {
             entity.CreatedBy = identity.Name;
         }
         if (!entity.CreatedOn.HasValue)
         {
             entity.CreatedOn = curUTCTime;
         }
         #endregion
         //
         #region check dtls
         if (saveOptions.IsChangeGroupDtl)
         {
             foreach (PM_ALT_NOTI_GROUP_DETAIL dtl in groupDtls)
             {
                 if (!dtl.NotiGroupDetailID.HasValue)
                 {
                     dtl.NotiGroupDetailID = Guid.NewGuid();
                 }
                 if (!dtl.NotiGroupID.HasValue)
                 {
                     dtl.NotiGroupID = entity.NotiGroupID;
                 }
                 if (string.IsNullOrEmpty(dtl.MemberID))
                 {
                     returnMessage = "Input parameter [GroupDtl.Member] can not be null.";
                     return;
                 }
             }
         }
         #endregion
         #endregion
         //
         #region save
         if (saveOptions.IsChangeGroup)
         {
             PM_ALT_NOTI_GROUP entityExisted = this.GetEntity(entity.NotiGroupID.Value);
             if (entityExisted == null)
             {
                 if (null != this.GetEntity(entity.GroupName))
                 {
                     returnMessage = "The item with the same name has existed.";
                     return;
                 }
                 //
                 entity.ModifiedBy = null;
                 entity.ModifiedOn = null;
                 //
                 this.Insert(entity);
             }
             else
             {
                 this.UpdateSome(entity);
             }
         }
         //
         if (saveOptions.IsChangeGroupDtl)
         {
             _PM_ALT_NOTI_GROUP_DETAILBO.SaveBatch(entity.NotiGroupID.Value, groupDtls, out returnMessage);
             //
             if (!string.IsNullOrEmpty(returnMessage))
             {
                 return;
             }
         }
         #endregion
     }
     catch (Exception ex)
     {
         returnMessage = ex.Message;
         return;
     }
 }