예제 #1
0
 public static int Insert(AgeDefinitions o)
 {
     try
     {
         string query = @"INSERT INTO ""AGE_DEFINITIONS"" (""NAME"", ""IS_ACTIVE"", ""NOTES"", ""DAYS"") VALUES (@Name, @IsActive, @Notes, @Days) returning ""ID"" ";
         List <Npgsql.NpgsqlParameter> parameters = new List <NpgsqlParameter>()
         {
             new NpgsqlParameter("@Name", DbType.String)
             {
                 Value = o.Name
             },
             new NpgsqlParameter("@IsActive", DbType.Boolean)
             {
                 Value = o.IsActive
             },
             new NpgsqlParameter("@Notes", DbType.String)
             {
                 Value = (object)o.Notes ?? DBNull.Value
             },
             new NpgsqlParameter("@Days", DbType.Int32)
             {
                 Value = o.Days
             }
         };
         object id = DBManager.ExecuteScalarCommand(query, CommandType.Text, parameters);
         AuditTable.InsertEntity("AgeDefinitions", id.ToString(), 1, DateTime.Now, 1);
         return(int.Parse(id.ToString()));
     }
     catch (Exception ex)
     {
         Log.InsertEntity("AgeDefinitions", "Insert", 1, ex.StackTrace.Replace("'", ""), ex.Message.Replace("'", ""));
     }
     return(-1);
 }
예제 #2
0
 public static AgeDefinitions GetAgeDefinitionsAsObject(DataTable dt)
 {
     foreach (DataRow row in dt.Rows)
     {
         try
         {
             AgeDefinitions o = new AgeDefinitions();
             o.Id       = Helper.ConvertToInt(row["ID"]);
             o.Name     = row["NAME"].ToString();
             o.IsActive = Helper.ConvertToBoolean(row["IS_ACTIVE"]);
             o.Notes    = row["NOTES"].ToString();
             o.Days     = Helper.ConvertToInt(row["DAYS"]);
             return(o);
         }
         catch (Exception ex)
         {
             Log.InsertEntity("AgeDefinitions", "GetAgeDefinitionsAsObject", 1, ex.StackTrace.Replace("'", ""), ex.Message.Replace("'", ""));
             throw ex;
         }
     }
     return(null);
 }
예제 #3
0
 public static int Update(AgeDefinitions o)
 {
     try
     {
         string query = @"UPDATE ""AGE_DEFINITIONS"" SET ""ID"" = @Id, ""NAME"" = @Name, ""IS_ACTIVE"" = @IsActive, ""NOTES"" = @Notes, ""DAYS"" = @Days WHERE ""ID"" = @Id ";
         List <Npgsql.NpgsqlParameter> parameters = new List <NpgsqlParameter>()
         {
             new NpgsqlParameter("@Name", DbType.String)
             {
                 Value = o.Name
             },
             new NpgsqlParameter("@IsActive", DbType.Boolean)
             {
                 Value = o.IsActive
             },
             new NpgsqlParameter("@Notes", DbType.String)
             {
                 Value = (object)o.Notes ?? DBNull.Value
             },
             new NpgsqlParameter("@Days", DbType.Int32)
             {
                 Value = o.Days
             },
             new NpgsqlParameter("@Id", DbType.Int32)
             {
                 Value = o.Id
             }
         };
         int rowAffected = DBManager.ExecuteNonQueryCommand(query, CommandType.Text, parameters);
         AuditTable.InsertEntity("AgeDefinitions", o.Id.ToString(), 2, DateTime.Now, 1);
         return(rowAffected);
     }
     catch (Exception ex)
     {
         Log.InsertEntity("AgeDefinitions", "Update", 2, ex.StackTrace.Replace("'", ""), ex.Message.Replace("'", ""));
     }
     return(-1);
 }