Ejemplo n.º 1
0
 public void SimpleUpdate(string tableName, string columnName, string value, int id)
 {
     using (IDbConnection connection = new SqlConnection(Helper.GetConnectionString("UserSupportDB")))
     {
         string sql       = $"UPDATE {tableName} SET {columnName} = @Value WHERE Id = @Id";
         var    exception = false;
         try
         {
             connection.Execute(sql, new { Value = value, Id = id });
         }
         catch (SqlException ex)
         {
             exception = true;
             if (ex.Message.Contains("UQ_POSITION_PositionName"))
             {
                 PositionExistException?.Invoke(this, null);
             }
             else if (ex.Message.Contains("UQ_DEPARTMENT_DepartmentName"))
             {
                 DepartmentExistException?.Invoke(this, null);
             }
             else if (ex.Message.Contains("UQ_REQUEST_THEME_ThemeName"))
             {
                 RequestThemeExistException?.Invoke(this, null);
             }
             else if (ex.Message.Contains("UQ_REQUEST_TYPE_TypeName"))
             {
                 RequestTypeExistException?.Invoke(this, null);
             }
         }
         if (!exception)
         {
             SuccessRecordUpdate?.Invoke(this, null);
         }
     }
 }
Ejemplo n.º 2
0
 public void SimpleInsert(string tableName, string value)
 {
     using (IDbConnection connection = new SqlConnection(Helper.GetConnectionString("UserSupportDB")))
     {
         string sql       = $"INSERT INTO {tableName} VALUES(@Value)";
         var    exception = false;
         try
         {
             connection.Execute(sql, new { Value = value });
         }
         catch (SqlException ex)
         {
             exception = true;
             if (ex.Message.Contains("UQ_POSITION_PositionName"))
             {
                 PositionExistException?.Invoke(this, null);
             }
             else if (ex.Message.Contains("UQ_DEPARTMENT_DepartmentName"))
             {
                 DepartmentExistException?.Invoke(this, null);
             }
             else if (ex.Message.Contains("UQ_REQUEST_THEME_ThemeName"))
             {
                 RequestThemeExistException?.Invoke(this, null);
             }
             else if (ex.Message.Contains("UQ_REQUEST_TYPE_TypeName"))
             {
                 RequestTypeExistException?.Invoke(this, null);
             }
         }
         if (!exception)
         {
             SuccessRecordInsert?.Invoke(this, null);
         }
     }
 }