public async Task <ActionResult <ResponseData> > Update(UserInfoDto userInfoDto) { if (userInfoDto != null && userInfoDto.Id > 0) { var userInfo = await _userRepository.Get(userInfoDto.Id, i => i.Include(x => x.Roles).ThenInclude(x => x.Role)); if (userInfo != null) { userInfoDto.MapTo(userInfo); if (userInfoDto.RoleIDS != null && userInfoDto.RoleIDS.Count > 0) { userInfo.Roles = new List <UserInRole>(); userInfoDto.RoleIDS.ForEach(x => userInfo.Roles?.Add(new UserInRole() { RoleId = x, UserId = userInfo.Id })); } var user = await _userInfoService.Update(userInfo); _responseData.Success = true; _responseData.Data = user; } else { _responseData.Success = false; _responseData.Message = "用户不存在"; } } return(_responseData); }
public async Task <ActionResult <ResponseData> > Create(UserInfoDto userInfoDto) { if (userInfoDto != null && !string.IsNullOrWhiteSpace(userInfoDto.UserName)) { UserInfo userInfo = new UserInfo(); userInfoDto.MapTo(userInfo); var uiInfo = await _userInfoService.GetUserList(x => x.UserName == userInfo.UserName); if (uiInfo != null && uiInfo.Count > 0) { _responseData.Success = false; _responseData.Message = "用户已存在"; } else { if (userInfo.Up.ContainsKey("roleIDS") && !string.IsNullOrWhiteSpace(userInfo.Up["roleIDS"].ToString())) { List <long> roleIDS = JsonConvert.DeserializeObject <List <long> >(userInfo.Up["roleIDS"].ToString()); if (roleIDS != null && roleIDS.Count > 0) { userInfo.Roles = new List <UserInRole>(); roleIDS?.ForEach(x => userInfo.Roles?.ToList().Add(new UserInRole() { RoleId = x })); } } userInfo.CreateUserID = long.Parse(User.FindFirst(x => x.Type == ClaimTypes.PrimarySid).Value); userInfo.CreateUserTime = DateTime.Now; var user = await _userInfoService.Insert(userInfo); _responseData.Success = true; _responseData.Data = user; } } return(_responseData); }