Exemplo n.º 1
0
        public async Task <IActionResult> GetCompanionNameAsync(GetDialogId _dialogId)
        {
            int dialogId = _dialogId.DialogId;

            if (dialogId == 0)
            {
                return(BadRequest());
            }
            Entities.User currentUser = (Entities.User)HttpContext.Items["User"];
            var           companions  = _context.ChatRooms.Include(o => o.Participants).ThenInclude(o => o.User).FirstOrDefaultAsync(o => o.Id == dialogId)
                                        .GetAwaiter().GetResult().Participants;

            companions.Remove(await _context.Participants.FirstOrDefaultAsync(o => o.ChatRoomId == dialogId && o.UserId == currentUser.Id));
            var result = companions.First().User;

            return(Ok(new { firstName = result.FirstName, lastName = result.LastName, id = result.Id }));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> GetAllMessagesAsync(GetDialogId dialogId)
        {
            var messages = await _context.Messages.Include(o => o.User).Where(o => o.ChatRoomId == dialogId.DialogId).ToListAsync();

            return(Ok(JsonSerializer.Serialize(messages)));
        }