Ejemplo n.º 1
0
        public async Task <ActionResult <ChatRoomViewModel[]> > Chats([FromBody] RecentChatsInput input)
        {
            string currentUserId = identity.CurrentUserId;
            var    chats         = await roomRepo.GetRecentChatRoomsAsync(currentUserId, input.Loaded.ToArray(), 10);

            return(chats.Select(x => mapper.Map <ChatRoomEntity, ChatRoomViewModel>(x)).ToArray());
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Index(string roomId = null)
        {
            string userId = this.identity.CurrentUserId;

            var rooms = (await roomRepo.GetRecentChatRoomsAsync(userId, null, 25));

            var reads = await roomRepo.GetHasUnreadAsync(rooms.Select(x => x.Id).ToArray(), userId);

            if (!String.IsNullOrEmpty(roomId) && rooms.Any(x => x.Id == roomId))
            {
                ViewBag.SelectedId = roomId.ToLower();
            }

            return(View(new IndexViewModel
            {
                Rooms = rooms.Select(x =>
                {
                    var vm = mapper.Map <ChatRoomEntity, ChatRoomViewModel>(x);
                    vm.HasUnread = reads[vm.Id];
                    vm.RoomName = vm.GetRoomName(userId);
                    return vm;
                })
            }));
        }