public async Task SendMessage(SendMessageInternalApiModel model) { var uri = UrlsConfig.Messaging.SendMessage(_remoteServiceBaseUrl); var content = new StringContent(JsonConvert.SerializeObject(model), Encoding.UTF8, "application/json"); var response = await _httpClient.PostAsync(uri, content); await response.EnsureSuccessStatusCodeCustom(); }
public async Task <ActionResult> SendMessage(SendMessageApiModel apiModel) { if (string.IsNullOrEmpty(apiModel.UsernameToSend)) { return(BadRequest("UsernameToSend is null or empty")); } if (string.IsNullOrEmpty(apiModel.MessageText)) { return(BadRequest("MessageText is null or empty")); } var userIdtoSend = await _identityService.GetUserIdByUsername(apiModel.UsernameToSend); if (userIdtoSend == Guid.Empty) { return(NotFound("User not found")); } var sendMessageModel = new SendMessageInternalApiModel(_identityService.GetCurrentUserId(), userIdtoSend, apiModel.MessageText); await _messagingService.SendMessage(sendMessageModel); return(Ok()); }