public void GetById(MyMeta.ITable table) { string args = string.Empty; string keys = string.Empty; string tableName = table.Name; GenTable genTable = new GenTable(table, _context); _output.tabLevel++; _output.tabLevel++; _output.autoTabLn("/// <summary>"); _output.autoTabLn("/// GetById and map the fields to the Model."); _output.autoTabLn("/// </summary>"); for (int i = 0; i < genTable.GetPrimaryKeyNames.Length; i++) { _output.autoTabLn("/// <param name=\"" + StringFormatter.CamelCasing(genTable.GetPrimaryKeyNames[i]) + "\"></param>"); } _output.autoTabLn("/// <returns></returns>"); _output.autoTab("public " + _util.BuildModelClassWithNameSpace(StringFormatter.CleanUpClassName(tableName)) + " GetById("); for (int i = 0; i < genTable.GetPrimaryKeyNames.Length; i++) { // type + " " + key name args += genTable.GetPrimaryKeyTypes[i] + " "; args += StringFormatter.CamelCasing(genTable.GetPrimaryKeyNames[i]) + ", "; keys += StringFormatter.CamelCasing(genTable.GetPrimaryKeyNames[i]) + ", "; } // trim the trailing ", " args = args.Substring(0, (args.Length - 2)); keys = keys.Substring(0, (keys.Length - 2)); _output.write(args); _output.writeln(")"); _output.autoTabLn("{"); _output.tabLevel++; _output.autoTabLn("using (var context = DataContextFactory.CreateContext())"); _output.autoTabLn("{"); _output.tabLevel++; _output.autoTabLn("return " + StringFormatter.CleanUpClassName(tableName) + "Mapper.ToBusinessObject(context." + StringFormatter.MakePlural(StringFormatter.CleanUpClassName(tableName))); string[] keysSplit = keys.Split(','); foreach (string key in keysSplit) { _output.tabLevel++; _output.autoTabLn(".Where(o => o." + _util.CleanUpProperty(key) + " == " + key + ")"); } _output.autoTabLn(".SingleOrDefault());"); _output.tabLevel--; _output.tabLevel--; _output.autoTabLn("}"); _output.tabLevel--; _output.autoTabLn("}"); _output.tabLevel--; _output.tabLevel--; }
public void cleanup_property_keeps_result_that_already_contains_underscore() { // Arrange CommonUtility util = new CommonUtility(); string propertyToClean = "Patent / Application_No. (first-class)"; // Act string actual = util.CleanUpProperty(propertyToClean, false, PropertyModifications.Underscore); string expected = "Patent___Application_No___first_class_"; // Assert Assert.AreEqual(expected, actual); }
public void cleanup_property_returns_compressed_property() { // Arrange CommonUtility util = new CommonUtility(); string propertyToClean = "Patent / Application No. (first-class)"; // Act string actual = util.CleanUpProperty(propertyToClean); string expected = "PatentApplicationNofirstclass"; // Assert Assert.AreEqual(expected, actual); }
public void cleanup_property_removes_underscore_in_original_property() { // Arrange CommonUtility util = new CommonUtility(); string propertyToClean = "Patent / Application_No. (first-class)"; // Act string actual = util.CleanUpProperty(propertyToClean); string expected = "PatentApplicationNofirstclass"; // Assert Assert.AreEqual(expected, actual); }
public void cleanupproperty_method_returns_column_name_unchanged_with_no_parameters() { // Arrange CommonUtility util = new CommonUtility(); string input = "test_column"; string expected = "test_column"; // Act string actual = util.CleanUpProperty(input); // Assert Assert.AreEqual(expected, actual); }
public void cleanupproperty_method_keeps_underscores_with_none_modifier_enabled() { // Arrange CommonUtility util = new CommonUtility(); string input = "test_column"; string expected = "test_column"; // Act string actual = util.CleanUpProperty(input, false, PropertyModifications.None); // Assert Assert.AreEqual(expected, actual); }
public void cleanupproperty_method_removes_dot_with_compress_modifier_enabled() { // Arrange CommonUtility util = new CommonUtility(); string input = "test.column"; string expected = "testcolumn"; // Act string actual = util.CleanUpProperty(input, false, PropertyModifications.Compress); // Assert Assert.AreEqual(expected, actual); }
public void RenderPropertyWithDataAnnotations() { IColumn column = m_IColumn; if (column.Name.ToLower() != script.Settings.DataOptions.VersionColumnName.ToLower()) { if (column.LanguageType.ToString().ToLower() == "string") { if (!column.IsNullable) { output.autoTabLn("[Required(ErrorMessage = \"" + StringFormatter.NormalizePropertyName(column.Name) + " is required.\")]"); if (column.Name.ToLower().Contains("phone")) { output.autoTabLn("[StringLength(14, ErrorMessage=\"" + column.Name + " is invalid. Format: (###) ###-####.\")]"); } else { if (!column.DataTypeName.Contains("text") && !column.DataTypeNameComplete.ToLower().Contains("nvarchar(max)")) { output.autoTabLn("[StringLength(" + column.CharacterMaxLength + ", ErrorMessage=\"" + StringFormatter.NormalizePropertyName(column.Name) + " must be between 1 and " + column.CharacterMaxLength + " characters.\")]"); } if (column.DataTypeName.Contains("text") || column.DataTypeNameComplete.ToLower().Contains("varchar(max)")) { output.autoTabLn("[DataType(DataType.MultilineText)]"); } } } else { if (column.DataTypeName.Contains("text") || column.DataTypeNameComplete.ToLower().Contains("varchar(max)")) { output.autoTabLn("[DataType(DataType.MultilineText)]"); } } output.autoTabLn(StringFormatter.CreateDisplayName(column.Name)); output.autoTabLn("public " + column.LanguageType + " " + _util.CleanUpProperty(column.Name) + " { get; set; }"); output.autoTabLn(""); } else if (column.IsInPrimaryKey) { output.autoTabLn("[ScaffoldColumn(false)]"); output.autoTabLn("public " + column.LanguageType + " " + _util.CleanUpProperty(column.Name) + " { get; set; }"); output.autoTabLn(""); } else { output.autoTabLn(StringFormatter.CreateDisplayName(column.Name)); if (!column.IsNullable) { output.autoTabLn("public " + column.LanguageType + " " + _util.CleanUpProperty(column.Name) + " { get; set; }"); output.autoTabLn(""); } else { if (column.DataTypeName == "bit") { output.autoTabLn("public " + column.LanguageType + " " + _util.CleanUpProperty(column.Name) + " { get; set; }"); output.autoTabLn(""); } else { output.autoTabLn("public " + column.LanguageType + "? " + _util.CleanUpProperty(column.Name) + " { get; set; }"); output.autoTabLn(""); } } } } else { if (!column.IsNullable) { if (column.LanguageType == "byte[]") { if (column.Name.ToLower() == script.Settings.DataOptions.VersionColumnName.ToLower()) { output.autoTabLn("[HiddenInput(DisplayValue=false)]"); output.autoTabLn("public string " + _util.CleanUpProperty(column.Name) + " { get; set; }"); output.autoTabLn(""); } else { output.autoTabLn("public " + column.LanguageType + " " + _util.CleanUpProperty(column.Name) + " { get; set; }"); output.autoTabLn(""); } } else { output.autoTabLn("public " + column.LanguageType + " " + _util.CleanUpProperty(column.Name) + " { get; set; }"); output.autoTabLn(""); } } else { if (column.LanguageType == "byte[]") { if (column.Name.ToLower() == script.Settings.DataOptions.VersionColumnName.ToLower()) { output.autoTabLn("[HiddenInput(DisplayValue=false)]"); output.autoTabLn("public string " + _util.CleanUpProperty(column.Name) + " { get; set; }"); output.autoTabLn(""); } else { output.autoTabLn("public " + column.LanguageType + " " + _util.CleanUpProperty(column.Name) + " { get; set; }"); output.autoTabLn(""); } } else { output.autoTabLn("public " + column.LanguageType + "? " + _util.CleanUpProperty(column.Name) + " { get; set; }"); output.autoTabLn(""); } } } }
public override void Render() { if (!_omitList.Where(o => o == this.Alias.ToLower()).Any()) { IColumn column = Column; if (column.Name.ToLower() != _script.Settings.DataOptions.VersionColumnName.ToLower()) { if (column.LanguageType.ToString().ToLower() == "string") { if (!column.IsNullable) { _output.autoTabLn("[Required(ErrorMessage = \"" + StringFormatter.NormalizePropertyName(column.Name) + " is required.\")]"); if (column.Name.ToLower().Contains("phone")) { _output.autoTabLn("[StringLength(14, ErrorMessage=\"" + column.Name + " is invalid. Format: (###) ###-####.\")]"); } else { if (!column.DataTypeName.Contains("text") && !column.DataTypeNameComplete.ToLower().Contains("nvarchar(max)")) { _output.autoTabLn("[StringLength(" + column.CharacterMaxLength + ", ErrorMessage=\"" + StringFormatter.NormalizePropertyName(column.Name) + " must be between 1 and " + column.CharacterMaxLength + " characters.\")]"); } if (column.DataTypeName.Contains("text") || column.DataTypeNameComplete.ToLower().Contains("varchar(max)")) { _output.autoTabLn("[DataType(DataType.MultilineText)]"); _output.autoTabLn("[UIHint(\"Editor\")]"); } } } else { if (column.DataTypeName.Contains("text") || column.DataTypeNameComplete.ToLower().Contains("varchar(max)")) { _output.autoTabLn("[DataType(DataType.MultilineText)]"); } } _output.autoTabLn(StringFormatter.CreateDisplayName(column.Name)); _output.autoTabLn("public " + column.LanguageType + " " + _util.CleanUpProperty(column.Name) + " { get; set; }"); _output.autoTabLn(""); } else if (column.IsInPrimaryKey) { _output.autoTabLn("[Key]"); _output.autoTabLn("public " + column.LanguageType + " " + _util.CleanUpProperty(column.Name) + " { get; set; }"); _output.autoTabLn(""); } else { _output.autoTabLn(StringFormatter.CreateDisplayName(column.Name)); if (!column.IsNullable) { _output.autoTabLn("public " + column.LanguageType + " " + _util.CleanUpProperty(column.Name) + " { get; set; }"); _output.autoTabLn(""); } else { if (column.DataTypeName == "bit") { _output.autoTabLn("public " + column.LanguageType + " " + _util.CleanUpProperty(column.Name) + " { get; set; }"); _output.autoTabLn(""); } else { _output.autoTabLn("public " + column.LanguageType + "? " + _util.CleanUpProperty(column.Name) + " { get; set; }"); _output.autoTabLn(""); } } } } else { if (!column.IsNullable) { if (column.DataTypeName == "timestamp") { } if (column.LanguageType == "byte[]") { if (column.Name.ToLower() == _script.Settings.DataOptions.VersionColumnName.ToLower()) { _output.autoTabLn("[HiddenInput(DisplayValue=false)]"); _output.autoTabLn("[Timestamp]"); _output.autoTabLn("public byte[] " + _util.CleanUpProperty(column.Name) + " { get; set; }"); _output.autoTabLn(""); } else { _output.autoTabLn("public " + column.LanguageType + " " + _util.CleanUpProperty(column.Name) + " { get; set; }"); _output.autoTabLn(""); } } else { _output.autoTabLn("public " + column.LanguageType + " " + _util.CleanUpProperty(column.Name) + " { get; set; }"); _output.autoTabLn(""); } } else { if (column.LanguageType == "byte[]") { if (column.Name.ToLower() == _script.Settings.DataOptions.VersionColumnName.ToLower()) { _output.autoTabLn("[HiddenInput(DisplayValue=false)]"); _output.autoTabLn("[Timestamp]"); _output.autoTabLn("public byte[] " + _util.CleanUpProperty(column.Name) + " { get; set; }"); _output.autoTabLn(""); } else { _output.autoTabLn("public " + column.LanguageType + " " + _util.CleanUpProperty(column.Name) + " { get; set; }"); _output.autoTabLn(""); } } else { _output.autoTabLn("public " + column.LanguageType + "? " + _util.CleanUpProperty(column.Name) + " { get; set; }"); _output.autoTabLn(""); } } } } }