Initial code commit.
This commit is contained in:
25
Sufi.Demo.PeopleDirectory.Persistence/Models/Audit/Audit.cs
Normal file
25
Sufi.Demo.PeopleDirectory.Persistence/Models/Audit/Audit.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using Sufi.Demo.PeopleDirectory.Domain.Common;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace Sufi.Demo.PeopleDirectory.Persistence.Models.Audit
|
||||
{
|
||||
public class Audit : IEntity<int>
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[Column(TypeName = "character varying(100)")]
|
||||
public string? UserId { get; set; }
|
||||
[Column(TypeName = "character varying(20)")]
|
||||
public string Type { get; set; } = null!;
|
||||
[Column(TypeName = "character varying(50)")]
|
||||
public string TableName { get; set; } = null!;
|
||||
public DateTime DateTime { get; set; }
|
||||
[Column(TypeName = "character varying(255)")]
|
||||
public string? OldValues { get; set; }
|
||||
[Column(TypeName = "character varying(255)")]
|
||||
public string? NewValues { get; set; }
|
||||
[Column(TypeName = "character varying(100)")]
|
||||
public string? AffectedColumns { get; set; }
|
||||
[Column(TypeName = "character varying(100)")]
|
||||
public string PrimaryKey { get; set; } = null!;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
using Microsoft.EntityFrameworkCore.ChangeTracking;
|
||||
using Sufi.Demo.PeopleDirectory.Application.Enums;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace Sufi.Demo.PeopleDirectory.Persistence.Models.Audit
|
||||
{
|
||||
public class AuditEntry(EntityEntry entry)
|
||||
{
|
||||
public EntityEntry Entry { get; } = entry;
|
||||
public string? UserId { get; set; }
|
||||
public string TableName { get; set; } = null!;
|
||||
public Dictionary<string, object?> KeyValues { get; } = new();
|
||||
public Dictionary<string, object?> OldValues { get; } = new();
|
||||
public Dictionary<string, object?> NewValues { get; } = new();
|
||||
public List<PropertyEntry> TemporaryProperties { get; } = new();
|
||||
public AuditType AuditType { get; set; }
|
||||
public List<string> ChangedColumns { get; } = new();
|
||||
public bool HasTemporaryProperties => TemporaryProperties.Any();
|
||||
|
||||
public Audit ToAudit()
|
||||
{
|
||||
var audit = new Audit
|
||||
{
|
||||
UserId = UserId,
|
||||
Type = AuditType.ToString(),
|
||||
TableName = TableName,
|
||||
DateTime = DateTime.UtcNow,
|
||||
PrimaryKey = JsonSerializer.Serialize(KeyValues),
|
||||
OldValues = OldValues.Count == 0 ? null : JsonSerializer.Serialize(OldValues),
|
||||
NewValues = NewValues.Count == 0 ? null : JsonSerializer.Serialize(NewValues),
|
||||
AffectedColumns = ChangedColumns.Count == 0 ? null : JsonSerializer.Serialize(ChangedColumns)
|
||||
};
|
||||
return audit;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Sufi.Demo.PeopleDirectory.Domain.Common;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace Sufi.Demo.PeopleDirectory.Persistence.Models.Identity
|
||||
{
|
||||
public class AppRole : IdentityRole, IAuditableEntity<string>
|
||||
{
|
||||
[Column(TypeName = "character varying(100)")]
|
||||
public string? Description { get; set; }
|
||||
public string? CreatedBy { get; set; }
|
||||
public DateTime CreatedOn { get; set; }
|
||||
public string? LastModifiedBy { get; set; }
|
||||
public DateTime? LastModifiedOn { get; set; }
|
||||
public virtual ICollection<AppRoleClaim> RoleClaims { get; set; }
|
||||
|
||||
public AppRole() : base()
|
||||
{
|
||||
RoleClaims = new HashSet<AppRoleClaim>();
|
||||
}
|
||||
|
||||
public AppRole(string roleName, string? description = null) : base(roleName)
|
||||
{
|
||||
RoleClaims = new HashSet<AppRoleClaim>();
|
||||
Description = description;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Sufi.Demo.PeopleDirectory.Domain.Common;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace Sufi.Demo.PeopleDirectory.Persistence.Models.Identity
|
||||
{
|
||||
public class AppRoleClaim : IdentityRoleClaim<string>, IAuditableEntity<int>
|
||||
{
|
||||
[Column(TypeName = "character varying(100)")]
|
||||
public string? Description { get; set; }
|
||||
[Column(TypeName = "character varying(100)")]
|
||||
public string? Group { get; set; }
|
||||
public string? CreatedBy { get; set; }
|
||||
public DateTime CreatedOn { get; set; }
|
||||
public string? LastModifiedBy { get; set; }
|
||||
public DateTime? LastModifiedOn { get; set; }
|
||||
|
||||
public AppRoleClaim() : base() { }
|
||||
|
||||
public AppRoleClaim(string? description = null, string? group = null) : base()
|
||||
{
|
||||
Description = description;
|
||||
Group = group;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Sufi.Demo.PeopleDirectory.Domain.Common;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace Sufi.Demo.PeopleDirectory.Persistence.Models.Identity
|
||||
{
|
||||
public class AppUser : IdentityUser<string>, IAuditableEntity<string>
|
||||
{
|
||||
public bool IsActive { get; set; }
|
||||
public bool IsDeleted { get; set; }
|
||||
public DateTime? DeletedOn { get; set; }
|
||||
public string? CreatedBy { get; set; }
|
||||
public DateTime CreatedOn { get; set; }
|
||||
public string? LastModifiedBy { get; set; }
|
||||
public DateTime? LastModifiedOn { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user