public static async Task <bool> SetRandomValueAsync(this ITableRow tableRow, Authentication authentication, string columnName) { var value = await GetRandomValueAsync(tableRow, columnName); if (value == null) { return(false); } var domain = tableRow.Content.Domain; var table = tableRow.Content.Table; var dataSet = domain.Source as CremaDataSet; var dataTable = dataSet.Tables[table.Name, table.Category.Path]; if (dataTable.Columns[columnName].Unique == true) { var expression = CremaDataExtensions.GenerateFieldExpression(columnName, value); var items = dataTable.Select(expression); if (items.Any() == true) { return(false); } } await tableRow.SetFieldAsync(authentication, columnName, value); return(true); }
public static async Task <bool> SetRandomValueAsync(this ITableRow tableRow, Authentication authentication) { var content = tableRow.Content; var table = content.Table; var columnInfo = table.TableInfo.Columns.Random(); var value = await GetRandomValueAsync(tableRow, columnInfo.Name); if (value == null) { return(false); } await tableRow.SetFieldAsync(authentication, columnInfo.Name, value); return(true); }