username@email.com
2024-09-03 b53678eec74cadc4d8d5773343b10ffa2adc5330
cylsg/cylsg.Application/Users/UserAppService.cs
@@ -286,5 +286,59 @@
      
        /// <summary>
        /// 保存用户信息
        /// </summary>
        /// <returns></returns>
        public async Task<bool> saveUser(UserDto userDto)
        {
            var UserID = App.User?.FindFirstValue("UserID");
            int userid = 0;
            string NickName = App.User?.FindFirstValue("NickName");
            if (!string.IsNullOrEmpty(UserID))
            {
                userid = int.Parse(UserID);
            }
            if (!string.IsNullOrEmpty(userDto.Nickname) && userDto.Nickname.Length > 100)
            {
                throw Oops.Oh("昵称长度过长!");
            }
            if (!string.IsNullOrEmpty(userDto.Avatar) && userDto.Avatar.Length > 500)
            {
                throw Oops.Oh("头像长度过长!");
            }
            var userRes = new BaseRepository<User>();
            bool res;
            var user = await userRes.GetByIdAsync(userid);
            if (!string.IsNullOrEmpty(userDto.Nickname))
                user.Nickname = userDto.Nickname;
            if (!string.IsNullOrEmpty(userDto.Avatar))
                user.Avatar = userDto.Avatar;
            user.UpDataBy = NickName;
            user.UpDataTime = DateTime.Now;
            res = await userRes.UpdateAsync(user);
            return res;
        }
    }
}