public void RefreshRoleUsers(ERRole role, IList <ERUser> users) { using (var odb = OdbFactory.Open(dbFileName)) { List <ERRelation> relations = odb.AsQueryable <ERRelation>().ToList(); foreach (var relation in relations) { if (relation.KeyId == role.Id && relation.RelationType == ERRelationType.RoleUser) { odb.Delete(relation); } } if (users != null) { List <ERRelation> newRelations = new List <ERRelation>(); foreach (var user in users) { newRelations.Add(new ERRelation() { Id = Guid.NewGuid(), KeyId = role.Id, ValueId = user.Id, RelationType = ERRelationType.RoleUser }); } odb.Store(newRelations); } } }
public void AddRole(ERRole role) { role.Id = Guid.NewGuid(); using (var odb = OdbFactory.Open(dbFileName)) { odb.Store(role); } }
public void AddRole(ERRole role) { role.Id = Guid.NewGuid(); using (var odb = OdbFactory.Open(dbFileName)) { odb.Store(role); } }
public void DeleteRole(ERRole role) { using (var odb = OdbFactory.Open(dbFileName)) { var db = odb.AsQueryable <ERRole>().Where(er => er.Id == role.Id).FirstOrDefault(); if (db != null) { odb.Delete(db); } } }
public void DeleteRole(ERRole role) { using (var odb = OdbFactory.Open(dbFileName)) { var db = odb.AsQueryable<ERRole>().Where(er => er.Id == role.Id).FirstOrDefault(); if (db != null) { odb.Delete(db); } } }
public ActionResult Edit(Guid id, ERRole Role) { try { ERRepositry.Instance.UpdateRole(Role); return RedirectToAction("Index"); } catch { return View(); } }
public ActionResult Create(ERRole Role) { try { ERRepositry.Instance.AddRole(Role); return RedirectToAction("Index"); } catch { return View(); } }
public List <ERUser> GetRoleUsers(ERRole role) { List <ERUser> users = new List <ERUser>(); using (var odb = OdbFactory.Open(dbFileName)) { List <ERRelation> relations = odb.AsQueryable <ERRelation>().Where(r => r.KeyId == role.Id && r.RelationType == ERRelationType.RoleUser).ToList(); users = odb.AsQueryable <ERUser>().Where(u => relations.Select(r => r.ValueId).Contains(u.Id)).ToList(); } return(users); }
/* * One Role has many operations * One user has many roles */ public List <EROperation> GetRoleOperations(ERRole role) { List <EROperation> operations = new List <EROperation>(); using (var odb = OdbFactory.Open(dbFileName)) { List <ERRelation> relations = odb.AsQueryable <ERRelation>().Where(r => r.KeyId == role.Id && r.RelationType == ERRelationType.RoleOperation).ToList(); operations = GetOperations().Where(oper => relations.Select(r => r.ValueId).Contains(oper.Id)).ToList(); } return(operations); }
// // GET: /Role/Create public ActionResult Create() { ERRole Role = new ERRole(); return View(Role); }
public void RefreshRoleUsers(ERRole role, IList<ERUser> users) { using (var odb = OdbFactory.Open(dbFileName)) { List<ERRelation> relations = odb.AsQueryable<ERRelation>().ToList(); foreach (var relation in relations) { if (relation.KeyId == role.Id && relation.RelationType == ERRelationType.RoleUser) { odb.Delete(relation); } } if (users != null) { List<ERRelation> newRelations = new List<ERRelation>(); foreach (var user in users) { newRelations.Add(new ERRelation() { Id = Guid.NewGuid(), KeyId = role.Id, ValueId = user.Id, RelationType = ERRelationType.RoleUser }); } odb.Store(newRelations); } } }
public List<ERUser> GetRoleUsers(ERRole role) { List<ERUser> users = new List<ERUser>(); using (var odb = OdbFactory.Open(dbFileName)) { List<ERRelation> relations = odb.AsQueryable<ERRelation>().Where(r => r.KeyId == role.Id && r.RelationType == ERRelationType.RoleUser).ToList(); users = odb.AsQueryable<ERUser>().Where(u => relations.Select(r => r.ValueId).Contains(u.Id)).ToList(); } return users; }
/* * One Role has many operations * One user has many roles */ public List<EROperation> GetRoleOperations(ERRole role) { List<EROperation> operations = new List<EROperation>(); using (var odb = OdbFactory.Open(dbFileName)) { List<ERRelation> relations = odb.AsQueryable<ERRelation>().Where(r => r.KeyId == role.Id && r.RelationType == ERRelationType.RoleOperation).ToList(); operations = GetOperations().Where(oper => relations.Select(r => r.ValueId).Contains(oper.Id)).ToList(); } return operations; }