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)); }
public async Task GetUserByAccount() { var userModel = new SysUser(); userModel.Id = Guid.NewGuid(); userModel.CreateTime = DateTime.Now; userModel.Account = "aruan"; userModel.Email = "*****@*****.**"; userModel.PassWord = "******".ToMd5Caps16(); _userRepository.AddUser(userModel); await _unitOfWork.SaveAsync(); var resultTrue = await _userRepository.GetUserByAccountAync("aruan"); Assert.True(resultTrue != null); var resultFalse = await _userRepository.GetUserByAccountAync("zhangsan"); Assert.False(resultFalse != null); }
public async Task <IActionResult> Post([FromBody] ToDoShareAddResource toDoShare) { if (toDoShare == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(new UnprocessableEntityObjectResult(ModelState)); } var userModel = await _sysUserRepository.GetUserByAccountAync(toDoShare.Account); if (userModel == null) { userModel = await _sysUserRepository.GetUserByEmailAync(toDoShare.Account); } if (userModel == null) { return(NotFound("用户不存在或已删除")); } var listModel = await _toDoListRepository.GetListById(toDoShare.ListId); if (listModel == null) { return(NotFound("内容不存在或已删除")); } if (userModel.Id.Equals(listModel.UserId)) { return(BadRequest("不能分享给自己")); } var toDoModel = new ToDoShare(); toDoModel.Id = Guid.NewGuid(); toDoModel.ListId = listModel.Id; toDoModel.UserId = userModel.Id; toDoModel.ShareTime = DateTime.Now; _toDoShareRepository.AddToDoShare(toDoModel); if (!await _unitOfWork.SaveAsync()) { throw new Exception("Error occurred when adding"); } _mailService.send(new MailOptions() { isbodyHtml = false, mailBody = $"有用户分享了待办列表《{listModel.Title}》给你", mailTitle = "待办列表分享", recipientArry = new string[1] { userModel.Email } }); return(Ok(toDoShare)); }