Ejemplo n.º 1
0
        public JsonResult GetFunctionTree(string test)
        {            
            int userId;
            string token;
            string message = string.Empty;
            bool success = false;
            List<TreeNodeModel> nodes = new List<TreeNodeModel>();
            if (GetToken(out userId, out token))
            {
                try
                {
                    DSClient client = new DSClient(Models.Const.ApplicationId);
                    var commands = client.GetCommands(userId, token, "", -1, -1);
                    var myCommands = client.GetRoleCommandsForUser(userId, token, userId);
                    var applications = client.GetApplications(userId, token, "", -1, -1).Where(c => !BuiltIns.ExcludeApplicationIds.Contains(c.Id)).ToList();

                    var me = client.GetUser(userId, token, userId);

                    Session["Me"] = me;
                    Session["Commands"] = myCommands.Select(t => t.Command_Id);

                    nodes.Add(GetCommandNode(commands, myCommands));
                    nodes.Add(GetApplicationNode(applications, commands, myCommands));
                    nodes.Add(GetPersonalNode());
                    success = true;
                }
                catch (DatabaseException exception)
                {
                    message = exception.Message;
                }
            }
            return Json(new { Success = success, Rows = nodes.ToArray(),Message = message }, JsonRequestBehavior.AllowGet);
        }
        public JsonResult GetMyCommands(int? appid)
        {
            int userId;
            string token;
            string message = string.Empty;
            bool success = false;
            if (GetToken(out userId, out token))
            {
                try
                {
                    DSClient client = new DSClient(Models.Const.ApplicationId);
                    var myCommands = client.GetRoleCommandsForUser(userId, token, userId);

                    bool hasAll = myCommands.FirstOrDefault(rc => rc.Application_Id == BuiltIns.AllApplication.Id && rc.Command_Id == BuiltIns.AllCommand.Id) != null;
                    if (!hasAll && appid.HasValue)
                    {
                        hasAll = myCommands.FirstOrDefault(rc => rc.Application_Id == appid.Value && rc.Command_Id == BuiltIns.AllCommand.Id) != null;
                    }
                    success = true;
                    if (hasAll)
                    {
                        return Json(new { Success = success, hasAll = true,Message = message }, JsonRequestBehavior.AllowGet);
                    }
                    else
                    {
                        var ids = appid.HasValue ? myCommands.Where(rc => rc.Application_Id == appid.Value).Select(rc => rc.Command_Id) : myCommands.Select(rc => rc.Command_Id);
                        return Json(new {Success = success, hasAll = false, cmdIds = ids.ToArray(), Message = message }, JsonRequestBehavior.AllowGet);
                    }
                }
                catch (DatabaseException exception)
                {
                    message = exception.Message;
                }

            }
            return Json(new { Success = success,Message = message }, JsonRequestBehavior.AllowGet);
        }