Skip to content

Commit

Permalink
🔥 Remove unncessary namespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
furkandeveloper committed Oct 10, 2021
1 parent 2b76ccb commit 0f6794a
Show file tree
Hide file tree
Showing 8 changed files with 121 additions and 11 deletions.
7 changes: 6 additions & 1 deletion EasyPermissionManagement.sln
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EasyPermissionManagement.En
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EasyPermissionManagement.PostgreSql", "src\EasyPermissionManagement.PostgreSql\EasyPermissionManagement.PostgreSql.csproj", "{4DF4757E-F6E8-4DBE-853B-2DAD3CA96395}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EasyPermissionManagement.AspNetCore", "src\EasyPermissionManagement.AspNetCore\EasyPermissionManagement.AspNetCore.csproj", "{4BE3AE6B-8935-41CB-B18E-3E598A5353EE}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EasyPermissionManagement.AspNetCore", "src\EasyPermissionManagement.AspNetCore\EasyPermissionManagement.AspNetCore.csproj", "{4BE3AE6B-8935-41CB-B18E-3E598A5353EE}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{CBB2864A-7715-4443-9F83-B21F8F21EEA5}"
ProjectSection(SolutionItems) = preProject
.gitignore = .gitignore
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
using EasyPermissionManagement.Core.Entities;
using EasyPermissionManagement.Core.Extensions;
using EasyPermissionManagement.Core.Statics;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EasyPermissionManagement.Core.Abstractions
namespace EasyPermissionManagement.Core.Abstractions
{
public interface IPermissionDefinationContext
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System.Threading.Tasks;

namespace EasyPermissionManagement.Core.Abstractions
{
public interface IPermissionProvider
{
Task ApplyPermissionAsync(string key, string identifierKey);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using EasyPermissionManagement.Core.Abstractions;
using EasyPermissionManagement.Core.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EasyPermissionManagement.Core.Concrete
{
public class PermissionProviderManager : IPermissionProvider
{
private readonly IEasyPermissionContext context;

public PermissionProviderManager(IEasyPermissionContext context)
{
this.context = context;
}
public virtual async Task ApplyPermissionAsync(string key, string identifierKey)
{
var permission = context.Get<Permission>().FirstOrDefault(a => a.Key == key);

if (permission is null)
{
throw new Exception($"Permission {key} Not Found");
}

await context.InsertAsync<IdentifierPermission>(new IdentifierPermission
{
PermissionId = permission.Id,
IdentifierKey = identifierKey
});
}
}
}
20 changes: 20 additions & 0 deletions src/EasyPermissionManagement.Core/Entities/IdentifierPermission.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EasyPermissionManagement.Core.Entities
{
public class IdentifierPermission : BaseEntity
{
public Guid PermissionId { get; set; }

public string IdentifierKey { get; set; }

/// <summary>
/// Relation property
/// </summary>
public virtual Permission Permission { get; set; }
}
}
5 changes: 5 additions & 0 deletions src/EasyPermissionManagement.Core/Entities/Permission.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,10 @@ public class Permission : BaseEntity
/// Provider of Permission
/// </summary>
public string Provider { get; set; }

/// <summary>
/// Relation property
/// </summary>
public virtual ICollection<IdentifierPermission> IdentifierPermissions { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public static class ServiceCollectionExtension
public static IServiceCollection AddEasyPermission(this IServiceCollection services)
{
services.AddTransient<IPermissionDefinationContext, PermissionDefinationContext>();
services.AddTransient<IPermissionProvider, PermissionProviderManager>();
return services;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using EasyPermissionManagement.Core.Entities;
using EasyPermissionManagement.EntityFrameworkCore.Generators;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.ChangeTracking.Internal;
using System;
using System.Collections.Generic;
using System.Linq;
Expand All @@ -25,6 +26,8 @@ protected EasyPermissionCoreDbContext(DbContextOptions options) : base(options)

#region Tables
public virtual DbSet<Permission> Permissions { get; set; }

public virtual DbSet<IdentifierPermission> IdentifierPermissions { get; set; }
#endregion


Expand Down Expand Up @@ -65,6 +68,47 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
.Property(p => p.Id)
.HasValueGenerator<GuidValueGenerator>()
.ValueGeneratedOnAdd();
entity
.HasMany(m => m.IdentifierPermissions)
.WithOne(o => o.Permission)
.HasForeignKey(fk => fk.PermissionId);
});

modelBuilder.Entity<IdentifierPermission>(entity =>
{
entity
.ToTable(nameof(IdentifierPermissions), "easy-permissions");
entity
.HasKey(pk=>pk.Id);
entity
.HasIndex(ix=> new { ix.CreateDate, ix.UpdateDate, ix.IdentifierKey});
entity
.Property(p=>p.IdentifierKey)
.IsRequired();
entity
.Property(p => p.CreateDate)
.HasValueGenerator<DateTimeValueGenerator>()
.ValueGeneratedOnAdd();
entity
.Property(p => p.UpdateDate)
.HasValueGenerator<DateTimeValueGenerator>()
.ValueGeneratedOnAdd();
entity
.Property(p => p.Id)
.HasValueGenerator<GuidValueGenerator>()
.ValueGeneratedOnAdd();
entity
.HasOne(o => o.Permission)
.WithMany(m => m.IdentifierPermissions)
.HasForeignKey(fk => fk.PermissionId);
});
}

Expand Down

0 comments on commit 0f6794a

Please sign in to comment.