コード例 #1
0
ファイル: UserAppService.cs プロジェクト: dotNetTreasury/Adnc
        public async Task Save(UserSaveInputDto saveDto)
        {
            var user = _mapper.Map <SysUser>(saveDto);

            if (user.ID < 1)
            {
                if (await _userRepository.ExistAsync(x => x.Account == user.Account))
                {
                    throw new BusinessException(new ErrorModel(HttpStatusCode.Forbidden, "用户已存在"));
                }

                user.ID       = IdGenerater.GetNextId();
                user.Salt     = SecurityHelper.GenerateRandomCode(5);
                user.Password = HashHelper.GetHashedString(HashType.MD5, user.Password, user.Salt);
                await _usrManager.AddUser(user);
            }
            else
            {
                await _userRepository.UpdateAsync(user,
                                                  x => x.Name,
                                                  x => x.DeptId,
                                                  x => x.Sex,
                                                  x => x.Phone,
                                                  x => x.Email,
                                                  x => x.Birthday,
                                                  x => x.Status);
            }
        }
コード例 #2
0
ファイル: AppServicesTests.cs プロジェクト: shanyipeng/Adnc
        public async Task TesUserAppService()
        {
            var user6 = new UserSaveInputDto()
            {
                ID       = 17,
                Account  = SecurityHelper.GenerateRandomCode(6),
                Avatar   = "",
                Birthday = DateTime.Now.AddYears(-20),
                DeptId   = 25,
                Email    = "*****@*****.**",
                Name     = "王大户",
                Password = "******",
                Phone    = "",
                Sex      = 1
            };
            var result6 = await _userAppService.Save(user6);

            Assert.Equal(1, result6);

            var reuslt5 = await _userAppService.GetPaged(new UserSearchDto()
            {
                PageIndex = 0, PageSize = 100
            });

            Assert.NotEmpty(reuslt5.Data);

            var result4 = await _userAppService.SetRole(new RoleSetInputDto { ID = 17, RoleIds = "2,3," });

            Assert.Equal(1, result4);

            var result3 = await _userAppService.ChangeStatus(17);

            Assert.Equal(1, result3);

            var result2 = await _userAppService.Delete(17);

            Assert.Equal(1, result2);

            var user1 = new UserSaveInputDto()
            {
                Account  = SecurityHelper.GenerateRandomCode(6),
                Avatar   = "",
                Birthday = DateTime.Now.AddYears(-20),
                DeptId   = 25,
                Email    = "*****@*****.**",
                Name     = "王大户",
                Password = "******",
                Phone    = "",
                Sex      = 1
            };
            var result1 = await _userAppService.Save(user1);

            Assert.Equal(1, result1);
        }
コード例 #3
0
ファイル: UserAppService.cs プロジェクト: liuguixin/Adnc
        public async Task <AppSrvResult> Update(UserSaveInputDto saveDto)
        {
            var user = _mapper.Map <SysUser>(saveDto);
            await _userRepository.UpdateAsync(user,
                                              x => x.Name,
                                              x => x.DeptId,
                                              x => x.Sex,
                                              x => x.Phone,
                                              x => x.Email,
                                              x => x.Birthday,
                                              x => x.Status);

            return(DefaultResult());
        }
コード例 #4
0
ファイル: UserAppService.cs プロジェクト: liuguixin/Adnc
        public async Task <AppSrvResult <long> > Add(UserSaveInputDto saveDto)
        {
            if (await _userRepository.AnyAsync(x => x.Account == saveDto.Account))
            {
                return(Problem(HttpStatusCode.BadRequest, "账号已经存在"));
            }

            var user = _mapper.Map <SysUser>(saveDto);

            user.Id       = IdGenerater.GetNextId();
            user.Salt     = SecurityHelper.GenerateRandomCode(5);
            user.Password = HashHelper.GetHashedString(HashType.MD5, user.Password, user.Salt);
            await _usrManager.AddUser(user);

            return(user.Id);
        }
コード例 #5
0
 public async Task <ActionResult> Update([FromBody] UserSaveInputDto userDto)
 {
     return(Result(await _userService.Update(userDto)));
 }
コード例 #6
0
 public async Task <ActionResult <long> > Add([FromBody] UserSaveInputDto userDto)
 {
     return(CreatedResult(await _userService.Add(userDto)));
 }
コード例 #7
0
 public async Task Save([FromBody] UserSaveInputDto userDto)
 {
     await _userService.Save(userDto);
 }