public static async Task <ResponseResult <Friendship[]> > GetUserFriends(string jwt) { using (var request = new HttpRequestMessage(HttpMethod.Get, $"{URI}/GetFriendships")) { var viewModel = new AuthorizedJwtViewModel { JwtFrom = jwt }; request.Content = new StringContent(JsonConvert.SerializeObject(viewModel), Encoding.UTF8, "application/json"); var response = await _client.SendAsync(request); if (response.IsSuccessStatusCode) { if (response.Content != null) { return(new ResponseResult <Friendship[]>( true, JsonConvert.DeserializeObject <Friendship[]>(await response.Content.ReadAsStringAsync()) )); } else { return(new ResponseResult <Friendship[]>(true, new Friendship[0])); } } return(new ResponseResult <Friendship[]>(false, new Friendship[0])); } }
public async Task <IActionResult> GetUser(AuthorizedJwtViewModel viewModel) { if (ModelState.IsValid) { // Verify the Jwt var fromEmail = await AuthorizationServices.VerifyToken(clientFactory, viewModel.JwtFrom); // Return Unauthorized if the Jwt was not validated if (fromEmail == null) { return(Unauthorized()); } try { return(Ok(JsonConvert.SerializeObject(await userRepo.GetUserAsync(fromEmail)))); } catch (UserDoesNotExistException) { return(BadRequest()); } } return(BadRequest(ModelState.Values)); }
public async Task <IActionResult> GetUserSessions(AuthorizedJwtViewModel viewModel) { if (ModelState.IsValid) { var fromEmail = await Services.AuthorizationServices.VerifyToken(clientFactory, viewModel.JwtFrom); if (fromEmail != null) { return(Ok( sessionRepository.GetMessageSessions(fromEmail) )); } } return(BadRequest(ModelState)); }
public async Task <IActionResult> GetFriendships(AuthorizedJwtViewModel viewModel) { if (ModelState.IsValid) { var fromEmail = await Services.AuthorizationServices.VerifyToken(_clientFactory, viewModel.JwtFrom); if (fromEmail != null) { return(Ok( JsonConvert.SerializeObject(friendshipRepo.GetAllFriendships(fromEmail)) )); } } return(BadRequest()); }
public static async Task <ResponseResult> PostProfileImage(string jwt, MediaFile image) { using (var request = new HttpRequestMessage(HttpMethod.Post, $"{URI}/PostProfileImage")) { var viewModel = new AuthorizedJwtViewModel { JwtFrom = jwt }; var stream = image.GetStream(); byte[] imageBytes = new byte[stream.Length]; await stream.ReadAsync(imageBytes, 0, imageBytes.Length); using (var content = new MultipartFormDataContent()) { content.Add(new StringContent(JsonConvert.SerializeObject(viewModel), Encoding.UTF8, "application/json"), "Auth"); content.Add(new ByteArrayContent(imageBytes), "files", Path.GetFileName(image.Path)); request.Content = content; var response = await _client.SendAsync(request); return(new ResponseResult(response.StatusCode == HttpStatusCode.OK)); } } }