示例#1
0
        public override void Initialize()
        {
            RoleCommandView rcv = GetConcretEntity <RoleCommandView>();

            sourceRoleVM.SetValue(ApplicationVM.LocalCache.AllRoleVMs.FirstOrDefault(r => r.Id == rcv.SourceRole_Id));
            targetRoleVM.SetValue(ApplicationVM.LocalCache.AllRoleVMs.FirstOrDefault(r => r.Id == rcv.TargetRole_Id));
            commandVM.SetValue(ApplicationVM.LocalCache.AllCommandVMs.FirstOrDefault(c => c.Id == rcv.Command_Id));
            base.Initialize();
        }
示例#2
0
 public JsonResult NewBackendRoleCommand()
 {
     try
     {
         RoleCommand rCmd = AddEntity <RoleCommand>(new RoleCommand {
             SourceRole_Id = BuiltIns.DefaultRole.Id, TargetRole_Id = BuiltIns.AllRole.Id, Command_Id = BuiltIns.DefaultBackendCommand.Id, IsManagerCommand = false, IsBuiltIn = false
         });
         RoleCommandView view = new RoleCommandView(rCmd, BuiltIns.DefaultBackendCommand);
         return(Json(new { Success = true, Model = new RoleCommandModel(view), Message = string.Empty }, JsonRequestBehavior.AllowGet));
     }
     catch (DatabaseException exception)
     {
         return(Json(new { Success = true, Message = exception.Message }, JsonRequestBehavior.AllowGet));
     }
 }
示例#3
0
 public RoleCommandModel(RoleCommandView rc)
     : base(rc)
 {
     if (rc != null)
     {
         Command_Id             = rc.Command_Id;
         IsManagerCommand       = rc.IsManagerCommand;
         SourceRole_Id          = rc.SourceRole_Id;
         TargetRole_Id          = rc.TargetRole_Id;
         Application_Id         = rc.Application_Id;
         Command_Name           = rc.Command_Name;
         CommandType            = rc.CommandType;
         Money                  = rc.Money;
         Command_Application_Id = rc.Command_Application_Id;
         ActionName             = rc.ActionName;
     }
 }
示例#4
0
        public T GetEntity <T>(int[] ids) where T : ModelEntity
        {
            DSClient client = new DSClient(Models.Const.ApplicationId);
            int      userId;
            string   token;

            if (GetToken(out userId, out token))
            {
                var t = typeof(T);
                if (t == typeof(Application))
                {
                    Application app = client.GetApplication(userId, token, ids[0]);
                    return(app as T);
                }
                else if (t == typeof(Role))
                {
                    Role role = client.GetRole(userId, token, ids[0]);
                    return(role as T);
                }
                else if (t == typeof(Image))
                {
                    Image image = client.GetImage(userId, token, ids[0]);
                    return(image as T);
                }
                else if (t == typeof(Command))
                {
                    Command cmd = client.GetCommand(userId, token, ids[0]);
                    return(cmd as T);
                }
                else if (t == typeof(RoleCommand))
                {
                    RoleCommand rc = client.GetRoleCommand(userId, token, ids[0]);
                    return(rc as T);
                }
                else if (t == typeof(RoleCommandView))
                {
                    RoleCommandView rc = client.GetRoleCommandView(userId, token, ids[0]);
                    return(rc as T);
                }
                else if (t == typeof(User))
                {
                    User user = client.GetUser(userId, token, ids[0]);
                    return(user as T);
                }
                else if (t == typeof(UserApplicationInfo))
                {
                    UserApplicationInfo info = client.GetUserInfo(userId, token, ids[0], ids[1]);
                    return(info as T);
                }
                else if (t == typeof(RoomGroup))
                {
                    RoomGroup roomGroup = client.GetRoomGroup(userId, token, ids[0]);
                    return(roomGroup as T);
                }
                else if (t == typeof(Room))
                {
                    Room room = client.GetRoom(userId, token, ids[0]);
                    return(room as T);
                }
                else if (t == typeof(RoomRole))
                {
                    RoomRole rRole = client.GetRoomRole(userId, token, ids[0], ids[1], ids[2]);
                    return(rRole as T);
                }
                else if (t == typeof(GiftGroup))
                {
                    GiftGroup giftGroup = client.GetGiftGroup(userId, token, ids[0]);
                    return(giftGroup as T);
                }
                else if (t == typeof(Gift))
                {
                    Gift gift = client.GetGift(userId, token, ids[0]);
                    return(gift as T);
                }
                else if (t == typeof(BlockType))
                {
                    BlockType b = client.GetBlockType(userId, token, ids[0]);
                    return(b as T);
                }
                else if (t == typeof(BlockList))
                {
                    BlockList b = client.GetBlockList(userId, token, ids[0]);
                    return(b as T);
                }
                else if (t == typeof(RoomRole))
                {
                    RoomRole rr = client.GetRoomRole(userId, token, ids[0], ids[1], ids[2]);
                    return(rr as T);
                }
                else if (t == typeof(RoomConfig))
                {
                    RoomConfig c = client.GetRoomConfig(userId, token, ids[0]);
                    return(c as T);
                }
            }
            return(null);
        }
示例#5
0
 public RoleCommandViewModel(RoleCommandView roleCommandView)
     : base(roleCommandView)
 {
 }
示例#6
0
        public JsonResult GetRoleCommands(string page, string pageSize, int cmdType, bool includeAll = false)
        {
            List <CommandModel> cmdMs = new List <CommandModel>();
            string message            = string.Empty;
            bool   success            = false;
            int    total = 0;
            string aId = Request.Form["aid"];
            string srId = Request.Form["srid"];
            int    appId = -1, sroleId = -1, troleId = -1;
            bool   good = true;

            if (!int.TryParse(aId, out appId) || !int.TryParse(srId, out sroleId))
            {
                good = false;
            }
            if (cmdType == BuiltIns.UserCommandType)
            {
                string trId = Request.Form["trid"];
                if (!int.TryParse(trId, out troleId))
                {
                    good = false;
                }
            }
            if (good)
            {
                string con = "([CommandType]&" + cmdType + ">0) AND ([Command_Application_Id]=1 OR [Command_Application_Id]=" + appId + ") AND [SourceRole_Id]=" + sroleId;
                if (cmdType == BuiltIns.UserCommandType)
                {
                    con += " AND [TargetRole_Id]=" + troleId;
                }
                try
                {
                    var cmds         = GetEntities <Command>(null, null, out total, "([CommandType]&" + cmdType + ">0)");
                    var roleCommands = GetEntities <RoleCommandView>(page, pageSize, out total, con);
                    foreach (var cmd in cmds)
                    {
                        Command c = cmd as Command;
                        if (!includeAll)
                        {
                            if (BuiltIns.ExcludeCommandIds.Contains(c.Id))
                            {
                                total--;
                                continue;
                            }
                        }
                        CommandModel model = new CommandModel(c);
                        foreach (var rc in roleCommands)
                        {
                            RoleCommandView rcv = rc as RoleCommandView;
                            if (rcv.Command_Id == c.Id)
                            {
                                model.Enabled      = true;
                                model.IsManagerCmd = rcv.IsManagerCommand?1:0;
                                break;
                            }
                        }
                        cmdMs.Add(model);
                    }
                    success = true;
                }
                catch (DatabaseException exception)
                {
                    message = exception.Message;
                }
            }
            return(Json(new { Success = success, Rows = cmdMs.ToArray(), Total = total, Message = message }, JsonRequestBehavior.AllowGet));
        }
示例#7
0
        public JsonResult SaveRoleCommands(List <CommandModel> cmds, int cmdType, int aid, int srid, string trid)
        {
            if (cmds == null)
            {
                cmds = new List <CommandModel>();
            }
            int tid = -1;

            if (cmdType == BuiltIns.UserCommandType)
            {
                if (!int.TryParse(trid, out tid))
                {
                    return(null);
                }
            }
            string con = "([CommandType]&" + cmdType + ">0) AND ([Command_Application_Id]=1 OR [Command_Application_Id]=" + aid + ") AND [SourceRole_Id]=" + srid;

            if (cmdType == BuiltIns.UserCommandType)
            {
                con += " AND [TargetRole_Id]=" + tid;
            }
            int    total   = 0;
            string message = string.Empty;
            bool   success = false;

            try
            {
                var roleCmds = GetEntities <RoleCommandView>(null, null, out total, con);
                foreach (var c in cmds)
                {
                    var roleCommand = roleCmds.FirstOrDefault(rc => (rc as RoleCommandView).Command_Id == c.Id) as RoleCommandView;
                    if (roleCommand == null)
                    {
                        AddEntity <RoleCommand>(new RoleCommand
                        {
                            Application_Id   = aid,
                            SourceRole_Id    = srid,
                            Command_Id       = c.Id,
                            IsManagerCommand = Convert.ToBoolean(c.IsManagerCmd),
                            TargetRole_Id    = (cmdType == BuiltIns.UserCommandType ? tid : BuiltIns.AllRole.Id)
                        });
                    }
                    else if (roleCommand.IsManagerCommand != Convert.ToBoolean(c.IsManagerCmd))
                    {
                        roleCommand.IsManagerCommand = Convert.ToBoolean(c.IsManagerCmd);
                        UpdateEntity(roleCommand);
                    }
                }
                foreach (var rc in roleCmds)
                {
                    RoleCommandView rcv = rc as RoleCommandView;
                    if (cmds.FirstOrDefault(c => c.Id == rcv.Command_Id) == null)
                    {
                        DeleteEntity(rcv);
                    }
                }
                success = true;
            }
            catch (DatabaseException exception)
            {
                message = exception.Message;
            }
            return(Json(new { Success = success, Message = message }, JsonRequestBehavior.AllowGet));
        }