Esempio n. 1
0
        public bool AddGroupPermission(int groupId, string permission, bool allowed = true)
        {
            SharpStarGroup group = GetGroup(groupId);

            if (group == null)
            {
                return(false);
            }

            using (var session = CreateSession())
            {
                using (var transaction = session.BeginTransaction())
                {
                    if (session.Query <SharpStarGroupPermission>().Any(p => p.Group.Id == group.Id && p.Permission.ToLower() == permission.ToLower()))
                    {
                        return(false);
                    }

                    var perm = new SharpStarGroupPermission
                    {
                        Group      = group,
                        Permission = permission,
                        Allowed    = allowed
                    };

                    session.Save(perm);

                    transaction.Commit();
                }
            }

            return(true);
        }
Esempio n. 2
0
        public bool RemoveGroupPermission(int groupId, string permission)
        {
            using (var session = CreateSession())
            {
                using (var transaction = session.BeginTransaction())
                {
                    SharpStarGroupPermission perm = session.Query <SharpStarGroupPermission>().SingleOrDefault(p => p.Group.Id == groupId && p.Permission.ToLower() == permission.ToLower());

                    if (perm == null)
                    {
                        return(false);
                    }

                    session.Delete(perm);

                    transaction.Commit();

                    return(true);
                }
            }
        }