-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added entities for Security area. #26
- Loading branch information
Showing
11 changed files
with
230 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/Server/DeploymentFramework/BusinessLogic/Domain/Security/Entities/Position.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Baud.Deployment.BusinessLogic.Domain.Security.Entities | ||
{ | ||
public class Position : EntityBase | ||
{ | ||
public short ID { get; set; } | ||
public string Name { get; set; } | ||
public bool IsActive { get; set; } | ||
|
||
public List<UserPositionLink> UserLinks { get; set; } | ||
public List<RolePositionLink> RoleLinks { get; set; } | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/Server/DeploymentFramework/BusinessLogic/Domain/Security/Entities/Role.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Baud.Deployment.BusinessLogic.Domain.Security.Entities | ||
{ | ||
public class Role : EntityBase | ||
{ | ||
public short ID { get; set; } | ||
public string Name { get; set; } | ||
public bool IsActive { get; set; } | ||
|
||
public List<RolePositionLink> PositionLinks { get; set; } | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/Server/DeploymentFramework/BusinessLogic/Domain/Security/Entities/RolePositionLink.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Baud.Deployment.BusinessLogic.Domain.Security.Entities | ||
{ | ||
public class RolePositionLink : EntityBase | ||
{ | ||
public short RoleID { get; set; } | ||
public short PositionID { get; set; } | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/Server/DeploymentFramework/BusinessLogic/Domain/Security/Entities/User.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Baud.Deployment.BusinessLogic.Domain.Security.Entities | ||
{ | ||
public class User : EntityBase | ||
{ | ||
public short ID { get; set; } | ||
public string Login { get; set; } | ||
public string FirstName { get; set; } | ||
public string LastName { get; set; } | ||
public string Email { get; set; } | ||
public string PasswordHash { get; set; } | ||
|
||
public DateTime ActiveFrom { get; set; } | ||
public DateTime? ActiveTo { get; set; } | ||
|
||
public string Note { get; set; } | ||
|
||
public bool IsSystemUser { get; set; } | ||
|
||
public List<UserPositionLink> PositionLinks { get; set; } | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/Server/DeploymentFramework/BusinessLogic/Domain/Security/Entities/UserPositionLink.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Baud.Deployment.BusinessLogic.Domain.Security.Entities | ||
{ | ||
public class UserPositionLink : EntityBase | ||
{ | ||
public short UserID { get; set; } | ||
public short PositionID { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Data.Entity; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Baud.Deployment.Database | ||
{ | ||
public class ContextBase : DbContext | ||
{ | ||
public void AttachAsModified<TEntity>(TEntity entity) where TEntity : class | ||
{ | ||
var dbEntityEntry = this.Entry(entity); | ||
if (dbEntityEntry.State == EntityState.Detached) | ||
{ | ||
Set<TEntity>().Attach(entity); | ||
} | ||
|
||
// marking all properties as modified | ||
dbEntityEntry.State = EntityState.Modified; | ||
} | ||
|
||
public void AttachAsModified<TEntity>(TEntity entity, params System.Linq.Expressions.Expression<Func<TEntity, object>>[] modifiedProperties) where TEntity : class | ||
{ | ||
var dbEntityEntry = this.Entry(entity); | ||
if (dbEntityEntry.State == EntityState.Detached) | ||
{ | ||
Set<TEntity>().Attach(entity); | ||
} | ||
|
||
if (modifiedProperties.Length > 0) | ||
{ | ||
for (int i = 0; i < modifiedProperties.Length; i++) | ||
{ | ||
var prop = dbEntityEntry.Property(modifiedProperties[i]); | ||
prop.IsModified = true; | ||
} | ||
} | ||
else | ||
{ | ||
// marking all properties as modified | ||
dbEntityEntry.State = EntityState.Modified; | ||
} | ||
} | ||
|
||
public void MarkReferenceModified<TEntity, TProperty>(TEntity entity, System.Linq.Expressions.Expression<Func<TEntity, TProperty>> navigationProperty) | ||
where TEntity : class | ||
where TProperty : class | ||
{ | ||
var reference = Entry(entity).Reference(navigationProperty); | ||
reference.CurrentValue = reference.CurrentValue; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/Server/DeploymentFramework/Database/Migrations/Configuration.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
namespace Baud.Deployment.Database.Migrations | ||
{ | ||
using System; | ||
using System.Data.Entity; | ||
using System.Data.Entity.Migrations; | ||
using System.Linq; | ||
|
||
internal sealed class Configuration : DbMigrationsConfiguration<Baud.Deployment.Database.BusinessContext> | ||
{ | ||
public Configuration() | ||
{ | ||
AutomaticMigrationsEnabled = true; | ||
ContextKey = "Baud.Deployment.Database.BusinessContext"; | ||
} | ||
|
||
protected override void Seed(Baud.Deployment.Database.BusinessContext context) | ||
{ | ||
// This method will be called after migrating to the latest version. | ||
|
||
// You can use the DbSet<T>.AddOrUpdate() helper extension method | ||
// to avoid creating duplicate seed data. E.g. | ||
// | ||
// context.People.AddOrUpdate( | ||
// p => p.FullName, | ||
// new Person { FullName = "Andrew Peters" }, | ||
// new Person { FullName = "Brice Lambson" }, | ||
// new Person { FullName = "Rowan Miller" } | ||
// ); | ||
// | ||
} | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
src/Server/DeploymentFramework/Database/SecurityContext.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Baud.Deployment.BusinessLogic.Domain.Security.Entities; | ||
|
||
namespace Baud.Deployment.Database | ||
{ | ||
public class SecurityContext : ContextBase | ||
{ | ||
protected override void OnModelCreating(System.Data.Entity.DbModelBuilder modelBuilder) | ||
{ | ||
modelBuilder.Entity<Role>() | ||
.ToTable("Role", "Security"); | ||
modelBuilder.Entity<Role>() | ||
.HasMany(r => r.PositionLinks); | ||
|
||
modelBuilder.Entity<RolePositionLink>() | ||
.ToTable("Role_Position", "Security") | ||
.HasKey(x => new { x.RoleID, x.PositionID }); | ||
|
||
modelBuilder.Entity<Position>() | ||
.ToTable("Position", "Security"); | ||
modelBuilder.Entity<Position>() | ||
.HasMany(p => p.RoleLinks); | ||
modelBuilder.Entity<Position>() | ||
.HasMany(p => p.UserLinks); | ||
|
||
modelBuilder.Entity<UserPositionLink>() | ||
.ToTable("User_Position", "Security") | ||
.HasKey(x => new { x.UserID, x.PositionID }); | ||
|
||
modelBuilder.Entity<User>() | ||
.ToTable("User", "Security"); | ||
modelBuilder.Entity<User>() | ||
.HasMany(u => u.PositionLinks); | ||
} | ||
} | ||
} |