/// <summary>
        /// Get the Securable Tree to display on the screen
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public SecurityAccessMaintenanceGetSecurableTreeResponse GetSecurableTree(
            SecurityAccessMaintenanceGetSecurableTreeRequest request)
        {
            //Get one level of securables
            var securableQueryable = _repository.GetAll <SecuritySecurable>(p => p.ChildSecuritySecurables);

            if (request != null && request.ParentSecuritySecurableId != null)
            {
                securableQueryable =
                    securableQueryable.Where(p => p.ParentSecuritySecurableId == request.ParentSecuritySecurableId);
            }
            else
            {
                securableQueryable =
                    securableQueryable.Where(p => p.ParentSecuritySecurableId == null);
            }

            //
            //Convert the linq query into the current tree model level
            //
            var securableTreeModel = securableQueryable.OrderBy(p => p.Name).Select(p => new SecuritySecurableTreeModel
            {
                id     = p.SecuritySecurableId.ToString(),
                parent = (p.ParentSecuritySecurableId == null ? "#" : p.ParentSecuritySecurableId.ToString()),
                text   = p.Name,
                state  = new SecuritySecurableTreeStateModel()
                {
                    disabled = false,
                    opened   = (p.ParentSecuritySecurableId == null ? true : false),
                    selected = false //(p.ParentSecuritySecurableId == null ? true : false)
                },
                children = p.ChildSecuritySecurables.Any()
            }).ToList();

            //
            //Select only the first parent node, in case we have multiple root securables
            //
            if (request != null && request.ParentSecuritySecurableId == null)
            {
                var firstNode = securableTreeModel.FirstOrDefault();
                if (firstNode != null)
                {
                    firstNode.state.selected = true;
                }
            }

            return(new SecurityAccessMaintenanceGetSecurableTreeResponse()
            {
                IsSuccessful = true,
                SecuritySecurableTreeModel = securableTreeModel
            });
        }
        /// <summary>
        /// Get a level of the securable tree. If parent securable id is not passed in,
        /// the root of the tree is obtained. Otherwise, the children of the parent id will be
        /// returned.
        /// </summary>
        /// <param name="model">Model</param>
        /// <returns>Displays the initial view of the page</returns>
        public virtual ActionResult GetSecurableTree(int?parentSecuritySecurableId)
        {
            var request = new SecurityAccessMaintenanceGetSecurableTreeRequest()
            {
                ParentSecuritySecurableId = parentSecuritySecurableId
            };
            var response = _service.GetSecurableTree(request);
            //Use Newtonsoft to to avoid error: "A circular reference was detected while serializing an object of type..."
            var json = JsonConvert.SerializeObject(response.SecuritySecurableTreeModel,
                                                   Formatting.None,
                                                   new JsonSerializerSettings()
            {
                ReferenceLoopHandling =
                    Newtonsoft.Json.ReferenceLoopHandling.Ignore
            });

            return(Content(json, "application/json"));
        }