public ActionResult <SysUserInfoDto> Get(int id) { SysUserInfoDto dto = new SysUserInfoDto(); dto.UserID = Guid.NewGuid().ToString(); dto.UserName = "******"; return(Ok(dto)); }
public async Task <MessageModel <string> > Put([FromBody] SysUserInfoDto sysUserInfo) { // 这里使用事务处理 var data = new MessageModel <string>(); try { _unitOfWork.BeginTran(); if (sysUserInfo != null && sysUserInfo.uID > 0) { // 无论 Update Or Add , 先删除当前用户的全部 U_R 关系 var usreroles = (await _userRoleServices.Query(d => d.UserId == sysUserInfo.uID)).Select(d => d.Id.ToString()).ToArray(); if (usreroles.Any()) { var isAllDeleted = await _userRoleServices.DeleteByIds(usreroles); if (!isAllDeleted) { return(Failed("服务器更新异常")); } } // 然后再执行添加操作 if (sysUserInfo.RIDs.Count > 0) { var userRolsAdd = new List <UserRole>(); sysUserInfo.RIDs.ForEach(rid => { userRolsAdd.Add(new UserRole(sysUserInfo.uID, rid)); }); await _userRoleServices.Add(userRolsAdd); } data.success = await _sysUserInfoServices.Update(_mapper.Map <SysUserInfo>(sysUserInfo)); _unitOfWork.CommitTran(); if (data.success) { data.msg = "更新成功"; data.response = sysUserInfo?.uID.ObjToString(); } } } catch (Exception e) { _unitOfWork.RollbackTran(); _logger.LogError(e, e.Message); } return(data); }
public async Task <MessageModel <string> > Post([FromBody] SysUserInfoDto sysUserInfo) { var data = new MessageModel <string>(); sysUserInfo.uLoginPWD = MD5Helper.MD5Encrypt32(sysUserInfo.uLoginPWD); sysUserInfo.uRemark = _user.Name; var id = await _sysUserInfoServices.Add(_mapper.Map <SysUserInfo>(sysUserInfo)); data.success = id > 0; if (data.success) { data.response = id.ObjToString(); data.msg = "添加成功"; } return(data); }