Exemplo n.º 1
0
        public bool ACLExists(MvcControllerACL acl)
        {
            try
            {
                int count = _context.MvcControllerACLs
                                .Where(x => x.Area == acl.Area
                                & x.Controller == acl.Controller
                                & x.Action == acl.Action
                                & x.RoleId == acl.RoleId).Count();

                return (count > 0);
            }
            catch (Exception ex)
            {
                throw new Exception("Error searching for ACL in database", ex);
            }
        }
Exemplo n.º 2
0
        public void AddAccess(string roleName, string area, string controller, string action)
        {
            ApplicationRole r = _context.Roles.FirstOrDefault(x => x.Name.ToLower() == roleName.ToLower());

            if (r != null)
            {
                MvcControllerACL acl = new MvcControllerACL()
                {
                    RecordId = Guid.NewGuid(),
                    Area = area,
                    Controller = controller,
                    Action = action,
                    RoleId = r.Id
                };

                if (!ACLExists(acl))
                {
                    _context.MvcControllerACLs.Add(acl);
                    _context.SaveChanges();
                }
            }
        }