public async Task <IActionResult> SendMessage(int roomId, NewMessageModel model) // message have weird order { Console.WriteLine("new message"); Console.WriteLine(model); // await chat.Clients.Group(roomName).SendAsync(); if (model.Content == "") { return(Conflict()); } var mess = await roomServices.CreatedMessageAsync(model.UserId, roomId, model.Content); if (mess == null) { return(Conflict()); } var messModel = new MessageModel { Content = mess.Content, Id = mess.Id, TimeCreated = MyTimeFormat.Short(mess.TimeCreated), UserName = mess.RoomUser.User.Username }; await chat.Clients.Group("room" + roomId).SendAsync("reciveMessage", messModel); return(Ok(mess)); }
public async Task <IActionResult> GetMessage(int roomId) { var mess = await roomServices.GetMessagesAsync(roomId); if (mess == null) { return(Conflict()); } var messModel = mess.Select(mess => new MessageModel { Id = mess.Id, Content = mess.Content, UserName = mess.RoomUser.User.Username, // TimeCreated = mess.TimeCreated.ToShortTimeString() + " - " + mess.TimeCreated.ToShortDateString(), TimeCreated = MyTimeFormat.Short(mess.TimeCreated), }) .OrderByDescending(m => m.Id) // RM 3 way 2 sort list .ToList(); // messModel.Sort((a,b) => b.Id - a.Id); // messModel.Sort((a,b) => b.Id.CompareTo(a.Id)); return(Ok(messModel)); }