chore: deleted all the stuff we don't need here
This commit is contained in:
@@ -1,32 +1,16 @@
|
||||
using GamificationService.Models.Database;
|
||||
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace GamificationService.Database;
|
||||
|
||||
|
||||
public class ApplicationContext : IdentityDbContext<ApplicationUser, ApplicationRole, long>
|
||||
public class ApplicationContext : DbContext
|
||||
{
|
||||
public ApplicationContext(DbContextOptions<ApplicationContext> options) : base(options)
|
||||
{
|
||||
}
|
||||
|
||||
public DbSet<Right> Rights { get; set; }
|
||||
public DbSet<RefreshToken> RefreshTokens { get; set; }
|
||||
public DbSet<ApplicationUser> Users { get; set; }
|
||||
public DbSet<ApplicationRole> Roles { get; set; }
|
||||
public DbSet<UserRole> UserRoles { get; set; }
|
||||
public DbSet<RoleRight> RoleRights { get; set; }
|
||||
public DbSet<UserProfile> UserProfiles { get; set; }
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
base.OnModelCreating(modelBuilder);
|
||||
|
||||
modelBuilder.Entity<UserRole>()
|
||||
.HasKey(ur => new { ur.UserId, ur.RoleId });
|
||||
|
||||
modelBuilder.Entity<RoleRight>()
|
||||
.HasKey(rr => new { rr.RoleId, rr.RightId });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,54 +1,5 @@
|
||||
using GamificationService.Models.Database;
|
||||
using GamificationService.Services.CurrentUsers;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.ChangeTracking;
|
||||
|
||||
namespace GamificationService.Database.Extensions;
|
||||
|
||||
public static class ChangeTrackerExtensions
|
||||
{
|
||||
public static void SetAuditProperties(this ChangeTracker changeTracker, ICurrentUserService currentUserService)
|
||||
{
|
||||
changeTracker.DetectChanges();
|
||||
IEnumerable<EntityEntry> entities =
|
||||
changeTracker
|
||||
.Entries()
|
||||
.Where(t => t.Entity is AuditableEntity &&
|
||||
(
|
||||
t.State == EntityState.Deleted
|
||||
|| t.State == EntityState.Added
|
||||
|| t.State == EntityState.Modified
|
||||
));
|
||||
|
||||
if (entities.Any())
|
||||
{
|
||||
DateTimeOffset timestamp = DateTimeOffset.UtcNow;
|
||||
|
||||
string user = currentUserService.GetCurrentUser().Login ?? "Unknown";
|
||||
|
||||
foreach (EntityEntry entry in entities)
|
||||
{
|
||||
AuditableEntity entity = (AuditableEntity)entry.Entity;
|
||||
|
||||
switch (entry.State)
|
||||
{
|
||||
case EntityState.Added:
|
||||
entity.CreatedOn = timestamp;
|
||||
entity.CreatedBy = user;
|
||||
entity.UpdatedOn = timestamp;
|
||||
entity.UpdatedBy = user;
|
||||
break;
|
||||
case EntityState.Modified:
|
||||
entity.UpdatedOn = timestamp;
|
||||
entity.UpdatedBy = user;
|
||||
break;
|
||||
case EntityState.Deleted:
|
||||
entity.UpdatedOn = timestamp;
|
||||
entity.UpdatedBy = user;
|
||||
entry.State = EntityState.Deleted;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
using GamificationService.Models.Database;
|
||||
using Microsoft.EntityFrameworkCore.Storage;
|
||||
|
||||
namespace GamificationService.Database.Repositories;
|
||||
@@ -8,12 +7,6 @@ public class UnitOfWork : IDisposable
|
||||
#region fields
|
||||
|
||||
private ApplicationContext _context;
|
||||
private GenericRepository<UserProfile> _userProfileRepository;
|
||||
private GenericRepository<ApplicationRole> _roleRepository;
|
||||
private GenericRepository<Right?> _rightRepository;
|
||||
private GenericRepository<RefreshToken> _refreshTokenRepository;
|
||||
private GenericRepository<RoleRight> _roleRightRepository;
|
||||
private GenericRepository<UserRole> _userRoleRepository;
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -28,78 +21,6 @@ public class UnitOfWork : IDisposable
|
||||
|
||||
#region Properties
|
||||
|
||||
public GenericRepository<UserProfile> UserProfileRepository
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this._userProfileRepository == null)
|
||||
{
|
||||
this._userProfileRepository = new GenericRepository<UserProfile>(_context);
|
||||
}
|
||||
return _userProfileRepository;
|
||||
}
|
||||
}
|
||||
|
||||
public GenericRepository<ApplicationRole> RoleRepository
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this._roleRepository == null)
|
||||
{
|
||||
this._roleRepository = new GenericRepository<ApplicationRole>(_context);
|
||||
}
|
||||
return _roleRepository;
|
||||
}
|
||||
}
|
||||
|
||||
public GenericRepository<Right?> RightRepository
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this._rightRepository == null)
|
||||
{
|
||||
this._rightRepository = new GenericRepository<Right?>(_context);
|
||||
}
|
||||
return _rightRepository;
|
||||
}
|
||||
}
|
||||
|
||||
public GenericRepository<RefreshToken> RefreshTokenRepository
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this._refreshTokenRepository == null)
|
||||
{
|
||||
this._refreshTokenRepository = new GenericRepository<RefreshToken>(_context);
|
||||
}
|
||||
return _refreshTokenRepository;
|
||||
}
|
||||
}
|
||||
|
||||
public GenericRepository<RoleRight> RoleRightRepository
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this._roleRightRepository == null)
|
||||
{
|
||||
this._roleRightRepository = new GenericRepository<RoleRight>(_context);
|
||||
}
|
||||
return _roleRightRepository;
|
||||
}
|
||||
}
|
||||
|
||||
public GenericRepository<UserRole> UserRoleRepository
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this._userRoleRepository == null)
|
||||
{
|
||||
this._userRoleRepository = new GenericRepository<UserRole>(_context);
|
||||
}
|
||||
return _userRoleRepository;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public bool Save()
|
||||
|
||||
Reference in New Issue
Block a user