public bool SetLocalUserinfo(BJUTHelperUserInfo user) { try { _dbService.DeleteAll <BJUTHelperUserInfo>(); _dbService.Insert <BJUTHelperUserInfo>(user); return(true); } catch { return(false); } }
public async Task <BJUTHelperUserInfo> EditUserinfoAsync(HttpBaseService httpService, BJUTHelperUserInfo userinfo, string avatarPath) { FileStream fileStream = null; try { var content = new MultipartFormDataContent(); content.Add(new StringContent(userinfo.Username), "Username"); content.Add(new StringContent(userinfo.NickName), "Nickname"); content.Add(new StringContent(userinfo.Gender.ToString()), "Gender"); content.Add(new StringContent(userinfo.Age.ToString()), "Age"); content.Add(new StringContent(userinfo.College.ToString()), "College"); if (!string.IsNullOrEmpty(avatarPath)) { fileStream = File.Open(avatarPath, FileMode.Open); StreamContent imageContent = imageContent = new StreamContent(fileStream); content.Add(imageContent, "avatar", Path.GetFileName(avatarPath)); } var re = await httpService.SendRequst(infoUri, HttpMethod.Post, content, Authorization : Services.UserService.Instance.Token); if (string.IsNullOrEmpty(re)) { throw new LoginTipException("服务故障"); } var model = Newtonsoft.Json.JsonConvert.DeserializeObject <LoginResultModel>(re); if (model == null) { throw new LoginTipException("服务故障"); } switch (model.Code) { case 200: return(model.Data); case 300: case 400: case 401: throw new LoginTipException(model.Msg); case 500: throw new LoginTipException("服务故障"); default: throw new LoginTipException($"未知异常 Code:{model.Code}"); } } catch (HttpRequestException) { throw new LoginTipException("服务故障"); } catch (Exception e) { throw; } finally { fileStream?.Dispose(); } }