Esempio n. 1
0
        public JsonResult SaveRoleUser()
        {
            string nodeFullID = Request["nodeFullID"], relationData = Request["relationData"];

            if (string.IsNullOrEmpty(nodeFullID) || string.IsNullOrEmpty(relationData))
            {
                return(Json(""));
            }
            var isTrue = GetValues(relationData, "Effective").First();

            string userID = GetValues(relationData, "ID").First();
            var    role   = entities.Set <S_A__RoleUser>().SingleOrDefault(c => c.RoleID == nodeFullID && c.UserID == userID);

            if (role == null && Convert.ToBoolean(isTrue))
            {
                S_A__RoleUser roleUser = new S_A__RoleUser();
                roleUser.RoleID = nodeFullID;
                roleUser.UserID = userID;
                entities.Set <S_A__RoleUser>().Add(roleUser);
            }
            else
            {
                entities.Set <S_A__RoleUser>().Remove(role);
            }
            var user = entities.Set <S_A_User>().FirstOrDefault(a => a.ID == userID);

            if (user != null)
            {
                user.ModifyTime = DateTime.Now;
            }

            entities.SaveChanges();
            return(Json("ok"));
        }
Esempio n. 2
0
        public JsonResult SetRoleUser(string RoleIDs, string UserIDs)
        {
            var userIds = UserIDs.Split(',');

            foreach (var userID in userIds)
            {
                entities.Set <S_A__RoleUser>().Delete(c => c.UserID == userID);

                foreach (var roleID in RoleIDs.Split(','))
                {
                    if (roleID == "")
                    {
                        continue;
                    }
                    var roleUser = new S_A__RoleUser();
                    roleUser.UserID = userID;
                    roleUser.RoleID = roleID;
                    entities.Set <S_A__RoleUser>().Add(roleUser);
                }
            }
            var users = this.entities.Set <S_A_User>().Where(a => userIds.Contains(a.ID)).ToList();

            users.Update(a => a.ModifyTime = DateTime.Now);
            entities.SaveChanges();
            return(Json(""));
        }
Esempio n. 3
0
        public JsonResult SaveRoleUsers(bool isSelect)
        {
            string nodeFullID = Request["nodeFullID"], relationData = Request["relationData"];

            if (string.IsNullOrEmpty(nodeFullID) || string.IsNullOrEmpty(relationData))
            {
                return(Json(""));
            }
            string[] userIDs = GetValues(relationData, "ID");
            if (userIDs.Length > 0)
            {
                foreach (var userID in userIDs)
                {
                    var role = entities.Set <S_A__RoleUser>().SingleOrDefault(c => c.RoleID == nodeFullID && c.UserID == userID);
                    if (role == null && isSelect)
                    {
                        S_A__RoleUser roleUser = new S_A__RoleUser();
                        roleUser.RoleID = nodeFullID;
                        roleUser.UserID = userID;
                        entities.Set <S_A__RoleUser>().Add(roleUser);
                    }
                    else
                    {
                        if (role != null && !isSelect)
                        {
                            entities.Set <S_A__RoleUser>().Remove(role);
                        }
                    }
                    var user = entities.Set <S_A_User>().FirstOrDefault(a => a.ID == userID);
                    if (user != null)
                    {
                        user.ModifyTime = DateTime.Now;
                    }
                }
                entities.SaveChanges();
            }
            return(Json("设置成功"));
        }