Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
starting to add some app stuff to configure database connection, etc.…
… recreated database to ensure it works correctly
- Loading branch information
Derick Bailey
committed
Nov 4, 2009
1 parent
5f0bfc2
commit a5a0624
Showing
9 changed files
with
133 additions
and
8 deletions.
There are no files selected for viewing
Binary file not shown.
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,20 @@ | ||
using FluentNHibernate.Cfg; | ||
using FluentNHibernate.Cfg.Db; | ||
using NHibernate.Cfg; | ||
using UoW; | ||
using UoW.NHibernate; | ||
|
||
namespace Security.Repository | ||
{ | ||
public static class RepoConfig | ||
{ | ||
public static IUnitOfWorkConfiguration GetConfiguration() | ||
{ | ||
Configuration config = Fluently.Configure() | ||
.Database(SQLiteConfiguration.Standard.UsingFile("security.s3db")) | ||
.Mappings(m => m.FluentMappings.AddFromAssemblyOf<SecurityRepository>()).BuildConfiguration(); | ||
|
||
return new NHibernateConfig(() => config, new StructureMapRepositoryFactory(), new ThreadStaticUnitOfWorkStorage()); | ||
} | ||
} | ||
} |
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,33 @@ | ||
using System.Collections.Generic; | ||
using NHibernate; | ||
using NHibernate.Criterion; | ||
using NHibernate.SqlCommand; | ||
using UoW.NHibernate; | ||
|
||
namespace Security.Repository | ||
{ | ||
public class SecurityRepository: NHibernateRepository, ISecurityRepository | ||
{ | ||
public IList<Permission> GetPermissionsForUserActivity(User user, string activity) | ||
{ | ||
ICriterion userIdMatches = Restrictions.Eq("Id", user.Id); | ||
ICriterion activityNameMatches = Restrictions.Eq("Name", activity); | ||
ICriterion userIdAliasMatches = Restrictions.Eq("u.Id", user.Id); | ||
|
||
DetachedCriteria groupPermissionCriteria = DetachedCriteria.For<Permission>() | ||
.SetProjection(Projections.Property("Role")) | ||
.CreateCriteria("Role").CreateCriteria("Users").Add(userIdMatches); | ||
ICriterion groupSubquery = Subqueries.PropertyIn("Role", groupPermissionCriteria); | ||
|
||
DetachedCriteria permissionCriteria = DetachedCriteria.For<Permission>() | ||
.CreateAlias("User", "u", JoinType.LeftOuterJoin) | ||
.Add(Restrictions.Or(userIdAliasMatches, groupSubquery)); | ||
permissionCriteria.CreateCriteria("Activity").Add(activityNameMatches); | ||
|
||
ICriteria executableCriteria = permissionCriteria.GetExecutableCriteria(Session); | ||
IList<Permission> permissions = executableCriteria.List<Permission>(); | ||
|
||
return permissions; | ||
} | ||
} | ||
} |
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
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
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 |
---|---|---|
|
@@ -2,6 +2,6 @@ namespace Security | |
{ | ||
public class User | ||
{ | ||
int Id { get; set; } | ||
public int Id { get; set; } | ||
} | ||
} |