Ejemplo n.º 1
0
        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);
                }
            }
        }
Ejemplo n.º 2
0
 public void AddRole(ERRole role)
 {
     role.Id = Guid.NewGuid();
     using (var odb = OdbFactory.Open(dbFileName))
     {
         odb.Store(role);
     }
 }
Ejemplo n.º 3
0
 public void AddRole(ERRole role)
 {
     role.Id = Guid.NewGuid();
     using (var odb = OdbFactory.Open(dbFileName))
     {
         odb.Store(role);
     }
 }
Ejemplo n.º 4
0
 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);
         }
     }
 }
Ejemplo n.º 5
0
 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);
         }
     }
 }
Ejemplo n.º 6
0
        public ActionResult Edit(Guid id, ERRole Role)
        {
            try
            {
                ERRepositry.Instance.UpdateRole(Role);

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
Ejemplo n.º 7
0
        public ActionResult Create(ERRole Role)
        {
            try
            {
                ERRepositry.Instance.AddRole(Role);

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
Ejemplo n.º 8
0
        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);
        }
Ejemplo n.º 9
0
        /*
         *  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);
        }
Ejemplo n.º 10
0
 //
 // GET: /Role/Create
 public ActionResult Create()
 {
     ERRole Role = new ERRole();
     return View(Role);
 }
Ejemplo n.º 11
0
        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);
                }
            }
        }
Ejemplo n.º 12
0
        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;
        }
Ejemplo n.º 13
0
        /*
         *  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;
        }