Пример #1
0
        public async Task <Message> PutUser(string id, [FromBody] Dictionary <string, object> dictionary)
        {
            if (!dictionary.ContainsKey("user") || !dictionary.ContainsKey("userRoleIdString"))
            {
                return(Message.Fail().Add("content", "参数错误"));
            }
            JObject          juser            = (JObject)dictionary["user"];
            UserModification userModification = juser.ToObject <UserModification>();
            string           userRoleIdString = (string)dictionary["userRoleIdString"];

            var dbItem = await _userRepository.GetSingleAsync(x => x.UserId == id);

            if (dbItem == null)
            {
                return(Message.NotFound());
            }
            userModification.UserId = id;
            _mapper.Map(userModification, dbItem);
            _userRepository.Update(dbItem);
            _userRoleRepository.UpdateRange(id, userRoleIdString);
            if (!await _unitOfWork.SaveAsync())
            {
                return(Message.ServerError());
            }
            return(Message.Ok());
        }
Пример #2
0
        public async Task <Message> PutEmp(string id, [FromBody] Dictionary <string, object> dictionary)
        {
            if (!dictionary.ContainsKey("password"))
            {
                return(Message.Fail().Add("content", "参数错误"));
            }
            string password = (string)dictionary["password"];

            var dbitem = await _userRepository.GetSingleAsync(x => x.UserId == id);

            if (dbitem == null)
            {
                return(Message.NotFound());
            }
            UserModification userModification = new UserModification();

            if (!string.IsNullOrEmpty(password) && password.Length < 6)
            {
                return(Message.Fail().Add("content", "密码长度小于6"));
            }
            userModification.UserId       = id;
            userModification.UserPassWord = password;
            _mapper.Map(userModification, dbitem);
            _userRepository.Update(dbitem);
            if (!await _unitOfWork.SaveAsync())
            {
                return(Message.ServerError());
            }
            return(Message.Ok());
        }
Пример #3
0
        public void openPanelUserModification()
        {
            this.panelMain.Controls.Clear();
            UserModification gui = new UserModification(this);

            gui.TopLevel   = false;
            gui.AutoScroll = true;
            this.panelMain.Controls.Add(gui);
            gui.Show();
            setMenuButton(false);
            setTestAnalysisButton(false);
        }
Пример #4
0
        public async Task <IActionResult> GrantUserPermissions(UserModification model)
        {
            IdentityResult result;

            if (ModelState.IsValid)
            {
                IdentityUser identityUser = await userManager.FindByIdAsync(model.UserId);

                foreach (string roleId in model.AddIds ?? new string[] { })
                {
                    IdentityRole role = await roleManager.FindByIdAsync(roleId);

                    if (role != null)
                    {
                        result = await userManager.AddToRoleAsync(identityUser, role.Name);

                        if (!result.Succeeded)
                        {
                            Errors(result);
                        }
                    }
                }
                foreach (string roleId in model.DeleteIds ?? new string[] { })
                {
                    IdentityRole role = await roleManager.FindByIdAsync(roleId);

                    if (role != null)
                    {
                        result = await userManager.RemoveFromRoleAsync(identityUser, role.Name);

                        if (!result.Succeeded)
                        {
                            Errors(result);
                        }
                    }
                }
            }

            if (ModelState.IsValid)
            {
                return(RedirectToAction(nameof(ManageUsers)));
            }
            else
            {
                return(await GrantUserPermissions(model.UserId));
            }
        }
Пример #5
0
        public async Task <IActionResult> Update(UserModification model)
        {
            IdentityResult result;

            if (ModelState.IsValid)
            {
                foreach (string roleName in model.RoleAdds ?? new string[] { })
                {
                    DatabaseTest5User user = await userManager.FindByIdAsync(model.UserId);

                    if (user != null)
                    {
                        result = await userManager.AddToRoleAsync(user, roleName);

                        if (!result.Succeeded)
                        {
                            Errors(result);
                        }
                    }
                }
                foreach (string roleName in model.RoleDels ?? new string[] { })
                {
                    DatabaseTest5User user = await userManager.FindByIdAsync(model.UserId);

                    if (user != null)
                    {
                        result = await userManager.RemoveFromRoleAsync(user, roleName);

                        if (!result.Succeeded)
                        {
                            Errors(result);
                        }
                    }
                }
            }

            if (ModelState.IsValid)
            {
                return(RedirectToAction(nameof(Index)));
            }
            else
            {
                return(await Update(model.UserId));
            }
        }