Jasinski Technical Wiki

Navigation

Home Page
Index
All Pages

Quick Search
»
Advanced Search »

Contributor Links

Create a new Page
Administration
File Management
Login/Logout
Your Profile

Other Wiki Sections

Software

PoweredBy

Page History: IAuditable Interface - .NET Framework

Compare Page Revisions



« Older Revision - Back to Page History - Newer Revision »


Page Revision: Mon, Oct 15, 2012, 8:07 AM


Implementation

When creating a new instance of an entity.

var i = new Invoice();
i.Created(user);

When updating an existing entity

i.Modified(user);

Applying to a database entity.

public partial class Invoice : IAuditable { }

Reusable Code

public interface IAuditable
{
    DateTime ModifyDate { get; set; }
    string ModifyUser { get; set; }
    DateTime CreateDate { get; set; }
    string CreateUser { get; set; }
}


public static class IAuditableExtension
{
    public static void Created(this IAuditable e, string user)
    {
        e.CreateDate = e.ModifyDate = DateTime.Now;
        e.CreateUser = e.ModifyUser = user;
    }

    public static void Modified(this IAuditable e, string user)
    {
        e.ModifyDate = DateTime.Now;
        e.ModifyUser = user;
    }
}

ScrewTurn Wiki version 3.0.1.400. Some of the icons created by FamFamFam. Except where noted, all contents Copyright © 1999-2024, Patrick Jasinski.