private async void CheckChannel() { if (mainChannel != null) { ChatChannelUser channelUser = mainChannel.ChatChannelUsers.Where(x => x.UserId == currentUser.Id).FirstOrDefault(); ChatMessage message = new ChatMessage(); message.ChatChannelUserId = channelUser.Id; message.CreatedOn = DateTime.Now; message.isCorrect = true; message.isRead = false; message.Text = currentMessageText; await messageService.SendMessage(message); } else { ChatChannel channel = null; if (playerAdvert != null && opponentAdvert == null) { channel = await messageService.GetChatChannel(playerAdvert.Id, playerAdvert.UserId, currentUser.Id, "Player"); } else if (playerAdvert == null && opponentAdvert != null) { channel = await messageService.GetChatChannel(opponentAdvert.Id, Convert.ToInt32(opponentAdvert.ownerId), currentUser.Id, "Opponent"); } if (channel != null) { mainChannel = channel; List <ChatChannelUser> channelUsers = mainChannel.ChatChannelUsers; ChatChannelUser channelUser = mainChannel.ChatChannelUsers.Where(x => x.UserId == currentUser.Id).FirstOrDefault(); ChatMessage message = new ChatMessage(); message.ChatChannelUserId = channelUser.Id; message.CreatedOn = DateTime.Now; message.isCorrect = true; message.isRead = false; message.Text = currentMessageText; await messageService.SendMessage(message); } else { if (playerAdvert != null && opponentAdvert == null) { channel = await messageService.CreateChannelAndSendMessage(playerAdvert.Id, playerAdvert.UserId, currentUser.Id, "Player", currentMessageText); } else if (playerAdvert == null && opponentAdvert != null) { channel = await messageService.CreateChannelAndSendMessage(opponentAdvert.Id, Convert.ToInt32(opponentAdvert.ownerId), currentUser.Id, "Opponent", currentMessageText); } if (channel != null) { mainChannel = channel; } } } }
public ResponseModel PostData(GetDataForMessaging request) { MessagingServices messagingServices = new MessagingServices(configuration); ResponseModel obj = messagingServices.SendMessage(request); ResponseModel response = new ResponseModel(); if (ModelState.IsValid) { if (obj.Data != null) { response.Data = obj.Data; response.StatusCode = Constants.StatusCode.Success; } else { response.Data = obj.Data; response.StatusCode = Constants.StatusCode.InternalServerError; response.Message = obj.Message; } } else { List <string> errorlist = new List <string>(); foreach (var modelState in ViewData.ModelState.Values) { foreach (var error in modelState.Errors) { errorlist.Add(error.ErrorMessage); } } response.Data = errorlist; response.StatusCode = StatusCodes.Status500InternalServerError; response.Message = Constants.Messages.SOMETHING_WENT_WRONG; return(response); } return(response); }