public IActionResult GetPermissionByCategory([FromRoute] int roleId)
        {
            var categories             = _context.Permission.GroupBy(p => p.Category).Select(c => c.Key);
            var permissionWithCategors = new List <PermissionModel.PermissionWithCategor>();

            foreach (var category in categories)
            {
                var permissions = _context.Permission.Where(p => p.Category == category).ToList();
                foreach (var permission in permissions)
                {
                    var p = new PermissionModel.PermissionWithCategor()
                    {
                        Id           = permission.Id,
                        Name         = permission.Name,
                        DisplayName  = permission.DisplayName,
                        Descriptions = permission.Description,
                        Category     = permission.Category,
                        IsCheck      = false
                    };
                    permissionWithCategors.Add(p);
                }

                foreach (var permission in permissionWithCategors)
                {
                    var permisionRole = _context.PermissionRoles.SingleOrDefault(p => p.RoleId == roleId && p.PermissionId == permission.Id);
                    if (permisionRole != null)
                    {
                        permission.IsCheck = true;
                    }
                }
            }


            return(Ok(permissionWithCategors));
        }
        public async Task <IActionResult> AddOrUpdatePermission([FromRoute] int id, [FromBody] PermissionModel.PermissionWithCategor permission)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (PermissionRoleExists(permission.Id, id))
            {
                var per = await _context.PermissionRoles.SingleOrDefaultAsync(m => m.PermissionId == permission.Id && m.RoleId == id);

                if (per == null)
                {
                    return(NotFound());
                }
                _context.PermissionRoles.Remove(per);
            }
            else
            {
                _context.PermissionRoles.Add(new PermissionRole()
                {
                    PermissionId = permission.Id, RoleId = id
                });
            }

            try
            {
                await _context.SaveChangesAsync();

                return(Ok(true));
            }
            catch (Exception ex)
            {
                return(Ok(false));
            }
        }