コード例 #1
0
        public async Task <AppHttpResponseMessageWrapper> SaveAvatarAsync(HttpPostedFileBase avatarInfo)
        {
            var modelInfo = new UploadAvatarInputModel
            {
                ProfileId   = HttpContext.Current.User.Identity.GetUserId(),
                ContentType = avatarInfo.ContentType,
                FileName    = avatarInfo.FileName
            };

            using (BinaryReader reader = new BinaryReader(avatarInfo.InputStream))
            {
                modelInfo.Content = reader.ReadBytes((int)avatarInfo.InputStream.Length);
            }


            var responce = await _httpClient.PostAsJsonAsync("api/profile/avatar/upload", modelInfo);

            var responceWrapper = new AppHttpResponseMessageWrapper(responce);

            if (!responce.IsSuccessStatusCode)
            {
                responceWrapper.ErrorMessage = await responce.Content.ReadAsStringAsync();
            }

            return(new AppHttpResponseMessageWrapper(responce));
        }
コード例 #2
0
        public async Task <AppHttpResponseMessageWrapper> RegisterMemberAsync(UserRegisterViewModel newUser)
        {
            AppHttpResponseMessageWrapper resultWrapper = null;

            try
            {
                var result = await _httpClient.PostAsJsonAsync("api/account/signup", newUser);

                resultWrapper = new AppHttpResponseMessageWrapper(result);

                if (resultWrapper.HttpResponseMessage.IsSuccessStatusCode)
                {
                    var idAndName = await resultWrapper.HttpResponseMessage.Content.ReadAsAsync <UserIdAndName>();

                    resultWrapper.UserName = idAndName.UserName;
                    resultWrapper.UserId   = idAndName.UserId;
                    return(resultWrapper);
                }

                if (result.StatusCode == HttpStatusCode.InternalServerError)
                {
                    var exception = await result.Content.ReadAsAsync <Exception>();

                    resultWrapper.ErrorMessage = exception.Message;
                }

                var jsonResult = await result.Content.ReadAsStringAsync();

                resultWrapper.ModelErrors = AppJsonUtility.UnwrapHttpBadRequestResult(jsonResult);
                return(resultWrapper);
            }
            catch (Exception exception)
            {
                resultWrapper?.ModelErrors.Add(exception.Message);
                return(resultWrapper);
            }
        }