Example #1
0
        /// <summary>
        /// Get with transaction
        /// </summary>
        public PM_ALT_EVENT_TYPE Get(object entityId, DbTransaction transaction)
        {
            ArgumentValidator.CheckForNullArgument(entityId, "entityId");
            ArgumentValidator.CheckForNullArgument(transaction, "transaction");

            PM_ALT_EVENT_TYPE PM_ALT_EVENT_TYPEEntity = null;

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

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

            return(PM_ALT_EVENT_TYPEEntity);
        }
Example #2
0
        private void UpdateAll(PM_ALT_EVENT_TYPE entity)
        {
            ArgumentValidator.CheckForNullArgument(entity, "entity");

            PersistentPM_ALT_EVENT_TYPE PM_ALT_EVENT_TYPEEntity = entity as PersistentPM_ALT_EVENT_TYPE;

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

                db.AddInParameter(dbCommand, "@EventTypeID", DbType.Guid, PM_ALT_EVENT_TYPEEntity.EventTypeID);
                db.AddInParameter(dbCommand, "@EventTypeName", DbType.String, PM_ALT_EVENT_TYPEEntity.EventTypeName);
                db.AddInParameter(dbCommand, "@EventTypeDesc", DbType.String, PM_ALT_EVENT_TYPEEntity.EventTypeDesc);
                db.AddInParameter(dbCommand, "@EventPriority", DbType.Int32, PM_ALT_EVENT_TYPEEntity.EventPriority);
                db.AddInParameter(dbCommand, "@EventBrief", DbType.String, PM_ALT_EVENT_TYPEEntity.EventBrief);
                db.AddInParameter(dbCommand, "@EventContent", DbType.String, PM_ALT_EVENT_TYPEEntity.EventContent);
                db.AddInParameter(dbCommand, "@NotiCnt", DbType.Int32, PM_ALT_EVENT_TYPEEntity.NotiCnt);
                db.AddInParameter(dbCommand, "@Category", DbType.String, PM_ALT_EVENT_TYPEEntity.Category);
                db.AddInParameter(dbCommand, "@CreatedBy", DbType.String, PM_ALT_EVENT_TYPEEntity.CreatedBy);
                db.AddInParameter(dbCommand, "@CreatedOn", DbType.DateTime, PM_ALT_EVENT_TYPEEntity.CreatedOn);
                db.AddInParameter(dbCommand, "@ModifiedBy", DbType.String, PM_ALT_EVENT_TYPEEntity.ModifiedBy);
                db.AddInParameter(dbCommand, "@ModifiedOn", DbType.DateTime, PM_ALT_EVENT_TYPEEntity.ModifiedOn);
                int result = db.ExecuteNonQuery(dbCommand);

                if (result == 0)
                {
                    throw new EntityNotFoundException();
                }
            }
            catch (Exception ex)
            {
                ExceptionPolicy.HandleException(ex, ExceptionPolicy.DataAccessDefaultPolicy);
            }
        }
 public void Remove(PM_ALT_EVENT_TYPE entity, out string returnMessage)
 {
     returnMessage = string.Empty;
     //
     try
     {
         DateTime?curUTCTime = UtilDAO.GetDatabaseUtcDatetime();
         //
         if (entity == null)
         {
             returnMessage = "Input parameter [PM_ALT_EVENT_TYPE entity] can not be null.";
             return;
         }
         if (!entity.EventTypeID.HasValue)
         {
             returnMessage = "[EventTypeID] can not be null.";
             return;
         }
         //
         this.Delete(entity);
     }
     catch (Exception ex)
     {
         returnMessage = ex.Message;
         return;
     }
 }
Example #4
0
        /// <summary>
        /// Insert with transaction
        /// </summary>
        public PM_ALT_EVENT_TYPE Insert(PM_ALT_EVENT_TYPE entity, DbTransaction transaction)
        {
            ArgumentValidator.CheckForNullArgument(entity, "entity");
            ArgumentValidator.CheckForNullArgument(transaction, "transaction");
            PersistentPM_ALT_EVENT_TYPE PM_ALT_EVENT_TYPEEntity = entity as PersistentPM_ALT_EVENT_TYPE;

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

                db.AddInParameter(dbCommand, "@EventTypeID", DbType.Guid, PM_ALT_EVENT_TYPEEntity.EventTypeID);
                db.AddInParameter(dbCommand, "@EventTypeName", DbType.String, PM_ALT_EVENT_TYPEEntity.EventTypeName);
                db.AddInParameter(dbCommand, "@EventTypeDesc", DbType.String, PM_ALT_EVENT_TYPEEntity.EventTypeDesc);
                db.AddInParameter(dbCommand, "@EventPriority", DbType.Int32, PM_ALT_EVENT_TYPEEntity.EventPriority);
                db.AddInParameter(dbCommand, "@EventBrief", DbType.String, PM_ALT_EVENT_TYPEEntity.EventBrief);
                db.AddInParameter(dbCommand, "@EventContent", DbType.String, PM_ALT_EVENT_TYPEEntity.EventContent);
                db.AddInParameter(dbCommand, "@NotiCnt", DbType.Int32, PM_ALT_EVENT_TYPEEntity.NotiCnt);
                db.AddInParameter(dbCommand, "@Category", DbType.String, PM_ALT_EVENT_TYPEEntity.Category);
                db.AddInParameter(dbCommand, "@CreatedBy", DbType.String, PM_ALT_EVENT_TYPEEntity.CreatedBy);
                db.AddInParameter(dbCommand, "@CreatedOn", DbType.DateTime, PM_ALT_EVENT_TYPEEntity.CreatedOn);
                db.AddInParameter(dbCommand, "@ModifiedBy", DbType.String, PM_ALT_EVENT_TYPEEntity.ModifiedBy);
                db.AddInParameter(dbCommand, "@ModifiedOn", DbType.DateTime, PM_ALT_EVENT_TYPEEntity.ModifiedOn);

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

            return(PM_ALT_EVENT_TYPEEntity as PM_ALT_EVENT_TYPE);
        }
Example #5
0
 public void Update(PM_ALT_EVENT_TYPE entity, bool updateAll, DbTransaction transaction)
 {
     if (!updateAll)
     {
         UpdateSome(entity, transaction);
     }
     else
     {
         UpdateAll(entity, transaction);
     }
 }
Example #6
0
 public void Update(PM_ALT_EVENT_TYPE entity, bool updateAll)
 {
     if (!updateAll)
     {
         UpdateSome(entity);
     }
     else
     {
         UpdateAll(entity);
     }
 }
        public void UpdateSome(PM_ALT_EVENT_TYPE entity)
        {
            try
            {
                ArgumentValidator.CheckForNullArgument(entity, "PM_ALT_EVENT_TYPE Entity");

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

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

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

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

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

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

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

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

            return(entity);
        }
Example #11
0
        private static PM_ALT_EVENT_TYPE ReadEntity(IDataReader dataReader)
        {
            PM_ALT_EVENT_TYPE PM_ALT_EVENT_TYPEEntity = new PM_ALT_EVENT_TYPE();
            object            value;


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

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

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

            value = dataReader["EventPriority"];
            if (value != DBNull.Value)
            {
                PM_ALT_EVENT_TYPEEntity.EventPriority = (Int32?)value;
            }

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

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

            value = dataReader["NotiCnt"];
            if (value != DBNull.Value)
            {
                PM_ALT_EVENT_TYPEEntity.NotiCnt = (Int32?)value;
            }

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

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

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

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

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

            return(PM_ALT_EVENT_TYPEEntity);
        }
Example #12
0
        private void UpdateSome(PM_ALT_EVENT_TYPE entity, DbTransaction transaction)
        {
            ArgumentValidator.CheckForNullArgument(entity, "entity");
            ArgumentValidator.CheckForNullArgument(transaction, "transaction");

            PersistentPM_ALT_EVENT_TYPE PM_ALT_EVENT_TYPEEntity = entity as PersistentPM_ALT_EVENT_TYPE;

            StringBuilder sqlUpdateSome = new StringBuilder();

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

            PropertyInfo[] propertyInfos        = PM_ALT_EVENT_TYPEEntity.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_EVENT_TYPEEntity, null);
                    ORProperty property      = EntityMapping[propertyInfo.Name];
                    if (!property.IsPrimaryKey)
                    {
                        if (!PM_ALT_EVENT_TYPEEntity.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 EventTypeID = @EventTypeID ");

            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);
            }
        }
Example #13
0
        /// <summary>
        /// Update with transaction
        /// </summary>

        public void Update(PM_ALT_EVENT_TYPE entity, DbTransaction transaction)
        {
            Update(entity, true, transaction);
        }
Example #14
0
        /// <summary>
        /// Update
        /// </summary>

        public void Update(PM_ALT_EVENT_TYPE entity)
        {
            Update(entity, true);
        }
 //
 public void Save(PM_ALT_EVENT_TYPE entity, IList <PM_ALT_EVENT_TYPE_GRP> mapDtls, EventTypeSaveOptions saveOptions, out string returnMessage)
 {
     returnMessage = string.Empty;
     //
     try
     {
         DateTime?curUTCTime = UtilDAO.GetDatabaseUtcDatetime();
         //
         #region check
         if (saveOptions == null)
         {
             returnMessage = "Input parameter [EventTypeSaveOptions saveOptions] can not be null.";
             return;
         }
         //
         if (entity == null)
         {
             returnMessage = "Input parameter [PM_ALT_EVENT_TYPE entity] can not be null.";
             return;
         }
         if (saveOptions.IsChangeMap)
         {
             if (mapDtls == null)
             {
                 returnMessage = "Input parameter [IList<PM_ALT_EVENT_TYPE_GRP> mapList] 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 type
         if (string.IsNullOrEmpty(entity.EventTypeName))
         {
             returnMessage = "[entity.EventTypeName] is required.";
             return;
         }
         //
         if (!entity.EventTypeID.HasValue)
         {
             entity.EventTypeID = 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.IsChangeMap)
         {
             foreach (PM_ALT_EVENT_TYPE_GRP dtl in mapDtls)
             {
                 if (!dtl.NotiEventGroupID.HasValue)
                 {
                     dtl.NotiEventGroupID = Guid.NewGuid();
                 }
                 if (!dtl.NotiGroupID.HasValue)
                 {
                     returnMessage = "Input parameter [NotiGroupID] can not be null.";
                     return;
                 }
                 if (!dtl.EventTypeID.HasValue)
                 {
                     returnMessage = "Input parameter [EventTypeID] can not be null.";
                     return;
                 }
             }
         }
         #endregion
         #endregion
         //
         #region save
         if (saveOptions.IsChangeType)
         {
             PM_ALT_EVENT_TYPE entityExisted = this.GetEntity(entity.EventTypeID.Value);
             if (entityExisted == null)
             {
                 if (null != this.GetEntity(entity.EventTypeName))
                 {
                     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.IsChangeMap)
         {
             _PM_ALT_EVENT_TYPE_GRPBO.SaveBatch(entity.EventTypeID.Value, mapDtls, out returnMessage);
             //
             if (!string.IsNullOrEmpty(returnMessage))
             {
                 return;
             }
         }
         #endregion
     }
     catch (Exception ex)
     {
         returnMessage = ex.Message;
         return;
     }
 }