/// <summary> /// Get with transaction /// </summary> public PM_ALT_NOTI Get(object entityId, DbTransaction transaction) { ArgumentValidator.CheckForNullArgument(entityId, "entityId"); ArgumentValidator.CheckForNullArgument(transaction, "transaction"); PM_ALT_NOTI PM_ALT_NOTIEntity = null; try { Database db = GetDatabaseInstance(); DbCommand dbCommand = db.GetSqlStringCommand(PM_ALT_NOTIDAO.SqlGet); db.AddInParameter(dbCommand, "@NotiGuid", DbType.Guid, entityId); using (IDataReader dataReader = db.ExecuteReader(dbCommand, transaction)) { if (dataReader.Read()) { PM_ALT_NOTIEntity = ReadEntity(dataReader); } } } catch (Exception ex) { ExceptionPolicy.HandleException(ex, ExceptionPolicy.DataAccessDefaultPolicy); } return(PM_ALT_NOTIEntity); }
private void UpdateAll(PM_ALT_NOTI entity, DbTransaction transaction) { ArgumentValidator.CheckForNullArgument(entity, "entity"); ArgumentValidator.CheckForNullArgument(transaction, "transaction"); PersistentPM_ALT_NOTI PM_ALT_NOTIEntity = entity as PersistentPM_ALT_NOTI; try { Database db = GetDatabaseInstance(); DbCommand dbCommand = db.GetSqlStringCommand(PM_ALT_NOTIDAO.SqlUpdate); db.AddInParameter(dbCommand, "@NotiGuid", DbType.Guid, PM_ALT_NOTIEntity.NotiGuid); db.AddInParameter(dbCommand, "@AlertID", DbType.Guid, PM_ALT_NOTIEntity.AlertID); db.AddInParameter(dbCommand, "@UserGuid", DbType.Guid, PM_ALT_NOTIEntity.UserGuid); db.AddInParameter(dbCommand, "@DepartmentGuid", DbType.Guid, PM_ALT_NOTIEntity.DepartmentGuid); db.AddInParameter(dbCommand, "@AgentGuid", DbType.Guid, PM_ALT_NOTIEntity.AgentGuid); db.AddInParameter(dbCommand, "@CreatedBy", DbType.String, PM_ALT_NOTIEntity.CreatedBy); db.AddInParameter(dbCommand, "@CreatedOn", DbType.DateTime, PM_ALT_NOTIEntity.CreatedOn); db.AddInParameter(dbCommand, "@UpdatedBy", DbType.String, PM_ALT_NOTIEntity.UpdatedBy); db.AddInParameter(dbCommand, "@UpdatedOn", DbType.DateTime, PM_ALT_NOTIEntity.UpdatedOn); 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 Insert(PM_ALT_NOTI entity) { ArgumentValidator.CheckForNullArgument(entity, "entity"); PersistentPM_ALT_NOTI PM_ALT_NOTIEntity = entity as PersistentPM_ALT_NOTI; try { Database db = GetDatabaseInstance(); DbCommand dbCommand = db.GetSqlStringCommand(PM_ALT_NOTIDAO.SqlInsert); db.AddInParameter(dbCommand, "@NotiGuid", DbType.Guid, PM_ALT_NOTIEntity.NotiGuid); db.AddInParameter(dbCommand, "@AlertID", DbType.Guid, PM_ALT_NOTIEntity.AlertID); db.AddInParameter(dbCommand, "@UserGuid", DbType.Guid, PM_ALT_NOTIEntity.UserGuid); db.AddInParameter(dbCommand, "@DepartmentGuid", DbType.Guid, PM_ALT_NOTIEntity.DepartmentGuid); db.AddInParameter(dbCommand, "@AgentGuid", DbType.Guid, PM_ALT_NOTIEntity.AgentGuid); db.AddInParameter(dbCommand, "@CreatedBy", DbType.String, PM_ALT_NOTIEntity.CreatedBy); db.AddInParameter(dbCommand, "@CreatedOn", DbType.DateTime, PM_ALT_NOTIEntity.CreatedOn); db.AddInParameter(dbCommand, "@UpdatedBy", DbType.String, PM_ALT_NOTIEntity.UpdatedBy); db.AddInParameter(dbCommand, "@UpdatedOn", DbType.DateTime, PM_ALT_NOTIEntity.UpdatedOn); int result = db.ExecuteNonQuery(dbCommand); } catch (Exception ex) { ExceptionPolicy.HandleException(ex, ExceptionPolicy.DataAccessDefaultPolicy); } return(PM_ALT_NOTIEntity as PM_ALT_NOTI); }
public void Update(PM_ALT_NOTI entity, bool updateAll, DbTransaction transaction) { if (!updateAll) { UpdateSome(entity, transaction); } else { UpdateAll(entity, transaction); } }
public void Update(PM_ALT_NOTI entity, bool updateAll) { if (!updateAll) { UpdateSome(entity); } else { UpdateAll(entity); } }
public void UpdateSome(PM_ALT_NOTI entity) { try { ArgumentValidator.CheckForNullArgument(entity, "PM_ALT_NOTI Entity"); pM_ALT_NOTIDAO.Update(entity, false); } catch (Exception ex) { ExceptionPolicy.HandleException(ex, ExceptionPolicy.BusinessLogicDefaultPolicy); } }
public void Delete(PM_ALT_NOTI entity) { try { ArgumentValidator.CheckForNullArgument(entity, "PM_ALT_NOTI Entity"); pM_ALT_NOTIDAO.Delete(entity.NotiGuid); } catch (Exception ex) { ExceptionPolicy.HandleException(ex, ExceptionPolicy.BusinessLogicDefaultPolicy); } }
public PM_ALT_NOTI GetEntity(Guid entityGuid) { PM_ALT_NOTI entity = null; try { ArgumentValidator.CheckForNullArgument(entityGuid, "PM_ALT_NOTI Guid"); entity = pM_ALT_NOTIDAO.Get(entityGuid); } catch (Exception ex) { ExceptionPolicy.HandleException(ex, ExceptionPolicy.BusinessLogicDefaultPolicy); } return(entity); }
public PM_ALT_NOTI Insert(PM_ALT_NOTI entity) { PM_ALT_NOTI newEntity = null; try { ArgumentValidator.CheckForNullArgument(entity, "PM_ALT_NOTI Entity"); newEntity = pM_ALT_NOTIDAO.Insert(entity); } catch (Exception ex) { ExceptionPolicy.HandleException(ex, ExceptionPolicy.BusinessLogicDefaultPolicy); } return(newEntity); }
public string saveUser(IList <CV_DEPARTMENT_QuaryParam> depQuaryParam) { if (depQuaryParam == null) { return("未选择联系人或应用"); } string returnMessage; try { DateTime dtNow = SSGlobalConfig.Now;; IList <PM_ALT_NOTI> altNotiList = new List <PM_ALT_NOTI>(); foreach (var item in depQuaryParam) { PM_ALT_NOTI altNotiEntity = new PM_ALT_NOTI(); altNotiEntity.AlertID = alertEntity.AlertID; altNotiEntity.UserGuid = item.userEntity.UserGuid; altNotiEntity.DepartmentGuid = item.DepartmentGuid; if (agentGuid != null && agentGuid != new Guid()) { altNotiEntity.AgentGuid = agentGuid; } altNotiEntity.CreatedBy = item.CreatedBy; altNotiEntity.CreatedOn = dtNow; altNotiEntity.UpdatedBy = item.UpdatedBy; altNotiEntity.UpdatedOn = item.UpdatedOn; altNotiList.Add(altNotiEntity); } //先删后增 pm_ALT_NOTIBO.SaveBatch((Guid)alertEntity.AlertID, altNotiList, out returnMessage); if (returnMessage == "") { returnMessage = "联系人设置成功"; } return(returnMessage); } catch (Exception ex) { returnMessage = ex.Message; return(returnMessage); } }
public void SaveBatch(Guid alertID, IList <PM_ALT_NOTI> notiGrps, out string returnMessage) { returnMessage = string.Empty; // try { if (notiGrps == null) { returnMessage = "Parameter [IList<ALERT_NOTI_GRP> members] can not be null."; return; } //删 pM_ALT_NOTIDAO.ClearDeletedByAlert(alertID); //增 foreach (PM_ALT_NOTI entity in notiGrps) { if (!entity.NotiGuid.HasValue) { entity.NotiGuid = Guid.NewGuid(); } // PM_ALT_NOTI entityExisted = this.GetEntity(entity.NotiGuid.Value); if (null == entityExisted) { // entity.RowDeleted = false; this.Insert(entity); } else { // entity.RowDeleted = false; this.UpdateSome(entity); } } // pM_ALT_NOTIDAO.ClearDeletedByAlert(alertID); } catch (Exception ex) { returnMessage = ex.Message; return; } }
private static PM_ALT_NOTI ReadEntity(IDataReader dataReader) { PM_ALT_NOTI PM_ALT_NOTIEntity = new PM_ALT_NOTI(); object value; value = dataReader["NotiGuid"]; if (value != DBNull.Value) { PM_ALT_NOTIEntity.NotiGuid = (Guid?)value; } value = dataReader["AlertID"]; if (value != DBNull.Value) { PM_ALT_NOTIEntity.AlertID = (Guid?)value; } value = dataReader["UserGuid"]; if (value != DBNull.Value) { PM_ALT_NOTIEntity.UserGuid = (Guid?)value; } value = dataReader["DepartmentGuid"]; if (value != DBNull.Value) { PM_ALT_NOTIEntity.DepartmentGuid = (Guid?)value; } value = dataReader["AgentGuid"]; if (value != DBNull.Value) { PM_ALT_NOTIEntity.AgentGuid = (Guid?)value; } value = dataReader["CreatedBy"]; if (value != DBNull.Value) { PM_ALT_NOTIEntity.CreatedBy = (String)value; } value = dataReader["CreatedOn"]; if (value != DBNull.Value) { PM_ALT_NOTIEntity.CreatedOn = (DateTime?)value; } value = dataReader["UpdatedBy"]; if (value != DBNull.Value) { PM_ALT_NOTIEntity.UpdatedBy = (String)value; } value = dataReader["UpdatedOn"]; if (value != DBNull.Value) { PM_ALT_NOTIEntity.UpdatedOn = (DateTime?)value; } return(PM_ALT_NOTIEntity); }
private void UpdateSome(PM_ALT_NOTI entity, DbTransaction transaction) { ArgumentValidator.CheckForNullArgument(entity, "entity"); ArgumentValidator.CheckForNullArgument(transaction, "transaction"); PersistentPM_ALT_NOTI PM_ALT_NOTIEntity = entity as PersistentPM_ALT_NOTI; StringBuilder sqlUpdateSome = new StringBuilder(); sqlUpdateSome.Append("UPDATE dbo.PM_ALT_NOTI SET "); PropertyInfo[] propertyInfos = PM_ALT_NOTIEntity.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_NOTIEntity, null); ORProperty property = EntityMapping[propertyInfo.Name]; if (!property.IsPrimaryKey) { if (!PM_ALT_NOTIEntity.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 NotiGuid = @NotiGuid "); 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 entity, DbTransaction transaction) { Update(entity, true, transaction); }
/// <summary> /// Update /// </summary> public void Update(PM_ALT_NOTI entity) { Update(entity, true); }