Skip to content

Commit b39d8d8

Browse files
author
phat
committed
feat(): add audit view model
1 parent 1158eb5 commit b39d8d8

File tree

2 files changed

+59
-2
lines changed

2 files changed

+59
-2
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
using Microsoft.EntityFrameworkCore;
2+
using Mix.Heart.Entities;
3+
using Mix.Heart.UnitOfWork;
4+
using System;
5+
6+
namespace Mix.Heart.ViewModel
7+
{
8+
public abstract partial class AuditViewModelBase<TDbContext, TEntity, TPrimaryKey, TView> : SimpleViewModelBase<TDbContext, TEntity, TPrimaryKey, TView>
9+
where TPrimaryKey : IComparable
10+
where TEntity : AuditEntityBase<TPrimaryKey>
11+
where TDbContext : DbContext
12+
where TView : AuditViewModelBase<TDbContext, TEntity, TPrimaryKey, TView>
13+
{
14+
#region Properties
15+
16+
public DateTime CreatedDateTime { get; set; }
17+
18+
public DateTime? LastModified { get; set; }
19+
20+
public string CreatedBy { get; set; }
21+
22+
public string ModifiedBy { get; set; }
23+
#endregion
24+
25+
#region Constructors
26+
27+
public AuditViewModelBase() : base()
28+
{
29+
}
30+
31+
public AuditViewModelBase(TDbContext context) : base(context)
32+
{
33+
}
34+
35+
public AuditViewModelBase(TEntity entity, UnitOfWorkInfo uowInfo) : base(entity, uowInfo)
36+
{
37+
}
38+
39+
public AuditViewModelBase(UnitOfWorkInfo unitOfWorkInfo) : base(unitOfWorkInfo)
40+
{
41+
}
42+
43+
#endregion
44+
45+
#region Overrides
46+
47+
public override void InitDefaultValues(string language = null, int? cultureId = null)
48+
{
49+
var now = DateTime.UtcNow;
50+
CreatedDateTime = now;
51+
LastModified = now;
52+
}
53+
54+
#endregion
55+
}
56+
}

src/mix.heart/ViewModel/ViewModelBase.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,9 @@ public ViewModelBase(UnitOfWorkInfo unitOfWorkInfo) : base(unitOfWorkInfo)
5454

5555
public override void InitDefaultValues(string language = null, int? cultureId = null)
5656
{
57-
CreatedDateTime = DateTime.UtcNow;
58-
LastModified = DateTime.UtcNow;
57+
var now = DateTime.UtcNow;
58+
CreatedDateTime = now;
59+
LastModified = now;
5960
Status = MixContentStatus.Published;
6061
IsDeleted = false;
6162
}

0 commit comments

Comments
 (0)