예제 #1
0
        public async Task Add()
        {
            var userModel = new SysUser();

            userModel.Id         = Guid.NewGuid();
            userModel.CreateTime = DateTime.Now;
            userModel.Account    = "lisi";
            userModel.Email      = "*****@*****.**";
            userModel.PassWord   = "******".ToMd5Caps16();
            _userRepository.AddUser(userModel);
            var result = await _unitOfWork.SaveAsync();

            Assert.True(result);
        }
예제 #2
0
        public async Task <IActionResult> Post([FromBody] UserAddResource user)
        {
            if (user == null)
            {
                return(BadRequest());
            }
            if (!ModelState.IsValid)
            {
                return(new UnprocessableEntityObjectResult(ModelState));
            }
            if (await _userRepository.GetUserByAccountAync(user.Account) != null)
            {
                return(BadRequest("用户已存在"));
            }
            if (await _userRepository.GetUserByEmailAync(user.Email) != null)
            {
                return(BadRequest("邮箱已存在"));
            }
            var userModel = _mapper.Map <SysUser>(user);

            userModel.Id         = Guid.NewGuid();
            userModel.CreateTime = DateTime.Now;
            userModel.PassWord   = user.PassWord.ToMd5Caps16();
            _userRepository.AddUser(userModel);
            if (!await _unitOfWork.SaveAsync())
            {
                throw new Exception("Error occurred when adding");
            }
            return(Ok(user));
        }