Migration File:
English: First lets add the proper fields to the table you wish to add the Logging to. Below is a sample migration file.
Español: Primero agregemos los puntos neccesarios a la table que necesitas. Abajo hay un ejemplo del archivo de migracion.
using FluentMigrator;
namespace SereneSample.Migrations.DefaultDB
{
[Migration(20161126210000)]
public class DefaultDB_20161126_210000_Logging : AutoReversingMigration
{
public override void Up()
{
Alter.Table("myTable")
.AddColumn("InsertUserId").AsInt32().Nullable()
.AddColumn("DeleteUserId").AsInt32().Nullable()
.AddColumn("UpdateUserId").AsInt32().Nullable()
.AddColumn("InsertOn").AsDateTime().Nullable()
.AddColumn("UpdatedOn").AsDateTime().Nullable()
.AddColumn("DeleteOn").AsDateTime().Nullable();
}
}
}
English: Add a new .cs called myTableLoggingRow.cs
Español: Agrege un nuevo .cs llamado myTableLoggingRow.cs:
namespace myProject.myModule.Entities
{
using Serenity.ComponentModel;
using Serenity.Data;
using Serenity.Data.Mapping;
using System;
public abstract class myTableLoggingRow : Row, ILoggingRow, IDeleteLogRow
{
protected myTableLoggingRow\(RowFieldsBase fields\) : base\(fields\)
{ loggingFields = \(myTableLoggingRowFields\)fields; }
\[NotNull, Insertable\(false\), Updatable\(false\)\]
public Int32? InsertUserId
{
get { return loggingFields.InsertUserId\[this\]; }
set { loggingFields.InsertUserId\[this\] = value; }
}
\[NotNull, Insertable\(false\), Updatable\(false\)\]
public DateTime? InsertOn
{
get { return loggingFields.InsertOn\[this\]; }
set { loggingFields.InsertOn\[this\] = value; }
}
\[Insertable\(false\), Updatable\(false\)\]
public Int32? UpdateUserId
{
get { return loggingFields.UpdateUserId\[this\]; }
set { loggingFields.UpdateUserId\[this\] = value; }
}
\[Insertable\(false\), Updatable\(false\)\]
public DateTime? UpdatedOn
{
get { return loggingFields.UpdatedOn\[this\]; }
set { loggingFields.UpdatedOn\[this\] = value; }
}
\[Insertable\(false\), Updatable\(false\)\]
public Int32? DeleteUserId
{
get { return loggingFields.UpdateUserId\[this\]; }
set { loggingFields.UpdateUserId\[this\] = value; }
}
\[Insertable\(false\), Updatable\(false\)\]
public DateTime? DeleteOn
{
get { return loggingFields.DeleteOn\[this\]; }
set { loggingFields.DeleteOn\[this\] = value; }
}
//Insert Fields
IIdField IInsertLogRow.InsertUserIdField
{
get { return loggingFields.InsertUserId; }
}
DateTimeField IInsertLogRow.InsertDateField
{
get { return loggingFields.InsertOn; }
}
//Update Fields
IIdField IUpdateLogRow.UpdateUserIdField
{
get { return loggingFields.UpdateUserId; }
}
DateTimeField IUpdateLogRow.UpdateDateField
{
get { return loggingFields.UpdatedOn; }
}
//Delete Fields
IIdField IDeleteLogRow.DeleteUserIdField
{
get { return loggingFields.DeleteUserId; }
}
DateTimeField IDeleteLogRow.DeleteDateField
{
get { return loggingFields.DeleteOn; }
}
private myTableLoggingRowFields loggingFields;
public class myTableLoggingRowFields : RowFieldsBase
{
public readonly Int32Field InsertUserId;
public readonly DateTimeField InsertOn;
public readonly Int32Field UpdateUserId;
public readonly DateTimeField UpdateOn;
public readonly Int32Field DeleteUserId;
public readonly DateTimeField DeleteOn;
public myTableLoggingRowFields\(string tableName\) : base\(tableName\) { }
}
}
}
English: In your myTableRow.cs replace the following 2 ‘Row’ references. At the top of the file replace
Español: En el myTableRow.cs remplace las 2 referencias a ‘Row’. Al principio del document remplaza :
public sealed class myTableRow : Row, IIdRow, INameRow
English: With
Español: Con
public sealed class myTableRow : myTableLoggingRow, IIdRow, INameRow
English: Then near the bottom of the file replace
Español: Cerca de el final del document:
public class RowFields : RowFieldsBase
English: With
Español: Con:
public class RowFields : myTableLoggingRowFields
English: Make sure that the RowFields class DOES NOT have the table fields for InsertUserId, InsertOn, UpdatedUserId, UpdateOn, DeleteUserId and DeleteOn. These are now referenced on the myTableLoggingRow.
Español: Assegurece que la classe RowFields NO tiene referencia a los puntos InsertUserId, InsertOn, UpdatedUserId, UpdateOn, DeleteUserId and DeleteOn. Estos ahora estan referenciados en el myTableLoggingRow.
English: To show the fields on the grid just add the Field reference onto the myTableColumns.cs You can also use the fields like any other field so you can also use a ForeignKey() on the field (such as InsertUserId) and then use it to reference the user table and get the user name. You can then display the user name on the grid instead of displaying the Id
Español: Para presentar los puntos en el grid, agrega los puntos en el document myTableColumns.cs. Puedes usar los puntos iguialmente a cualquier otro punto asi que puedes usar el ForeignKey() en un punto (como el InsertUserId) y despues usarlo para referenciar la table de usuarios y tomar el nombre del usuario. Entonces podras presenter el nombre del usuario en ves del ID del usuario.
Example
In myTableLoggingRow.cs:
[NotNull, Insertable(false), Updatable(false)]
[DisplayName("User Name - Insert"), ForeignKey("dbo.Users","UserId"), LeftJoin("inID")]
public Int32? InsertUserId
{
get { return loggingFields.InsertUserId\[this\]; }
set { loggingFields.InsertUserId\[this\] = value; }
}
In myTableRow.cs:
[NotNull, Insertable(false), Updatable(true), Expression("inID.Username")]
public String InsertUserName
{
get { return Fields.InsertUserName\[this\]; }
set { Fields.InsertUserName\[this\] = value; }
}
In myTableColumns.cs add the field:
public String InsertUserName { get; set; }