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); } }
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(); } } }