public async Task <ResponseResult <int> > Edit_Save()
        {
            //获取参数
            StreamReader          streamReader          = new StreamReader(Request.Body);
            var                   paramStr              = streamReader.ReadToEnd();
            RequestParamterHelper requestParamterHelper = new RequestParamterHelper(paramStr);


            var       id        = int.Parse(requestParamterHelper.GetParamValue("id")[0]);
            AdminUser adminUser = await _userService.GetAdminUserTrackingAsync(id);

            adminUser.Name = requestParamterHelper.GetParamValue("name")[0];
            //adminUser.Password = requestParamterHelper.GetParamValue("password")[0];
            var phonedic = requestParamterHelper.GetParamValue("phone");

            if (phonedic != null && phonedic.Count > 0)
            {
                adminUser.Phone = phonedic[0];
            }
            adminUser.Gender = int.Parse(requestParamterHelper.GetParamValue("gender")[0]);
            adminUser.UserRoles.RemoveRange(0, adminUser.UserRoles.Count);
            foreach (var it in requestParamterHelper.GetParamValue("roleId"))
            {
                var roleId        = int.Parse(it);
                var adminUserRole = new AdminUserRole
                {
                    RoleId = roleId
                };
                adminUser.UserRoles.Add(adminUserRole);
            }
            //adminUser.Password = MD5Helper.MD5Crypto16(adminUser.Password);
            var serviceResult = await _userService.UpdateModelAsync(adminUser);

            return(new ResponseResult <int>(true, serviceResult));
        }
        public async Task <ResponseResult <int> > Add_Save()
        {
            //获取参数
            StreamReader          streamReader          = new StreamReader(Request.Body);
            var                   paramStr              = streamReader.ReadToEnd();
            RequestParamterHelper requestParamterHelper = new RequestParamterHelper(paramStr);

            AdminUser adminUser = new AdminUser();

            adminUser.Name = requestParamterHelper.GetParamValue("name")[0];
            var user = await _userService.GetAdminUserByNameAsync(adminUser.Name);

            if (user != null)
            {
                return(new ResponseResult <int>(false, -1));
            }
            //adminUser.Password = requestParamterHelper.GetParamValue("password")[0];
            var phonedic = requestParamterHelper.GetParamValue("phone");

            if (phonedic != null && phonedic.Count > 0)
            {
                adminUser.Phone = phonedic[0];
            }

            adminUser.Gender    = int.Parse(requestParamterHelper.GetParamValue("gender")[0]);
            adminUser.UserRoles = new List <AdminUserRole>();
            foreach (var it in requestParamterHelper.GetParamValue("roleId"))
            {
                var roleId        = int.Parse(it);
                var adminUserRole = new AdminUserRole
                {
                    RoleId = roleId
                };
                adminUser.UserRoles.Add(adminUserRole);
            }

            //adminUser.Password = MD5Helper.MD5Crypto16("123456");
            //123456 加密后的值
            adminUser.Password = "******";

            var serviceResult = await _userService.AddModelAsync(adminUser);

            return(new ResponseResult <int>(true, serviceResult));
        }
示例#3
0
        public async Task <ResponseResult <int> > Add_Save()
        {
            //获取参数
            var streamReader = new StreamReader(Request.Body);
            var paramStr     = streamReader.ReadToEnd();
            RequestParamterHelper requestParamterHelper = new RequestParamterHelper(paramStr);

            var roleNames = requestParamterHelper.GetParamValue("roleName");
            var roleName  = roleNames[0];
            var menus     = requestParamterHelper.GetParamValue("menuId");

            var role = new AdminRole();

            role.Name = roleName;

            var serviceResult = await _roleService.AddRoleAsync(role, menus.Select(m => int.Parse(m)).ToList());

            return(new ResponseResult <int>(true, serviceResult));
        }