Ejemplo n.º 1
0
        public async Task <JsonResult> NameListData()
        {
            if (!this.User.Identity.IsAuthenticated)
            {
                return(Json(null, JsonRequestBehavior.AllowGet));
            }

            var onlineUserIds = (await _onlineUserService
                                 .GetOnlineUsers()
                                 .Select(u => u.Id)
                                 .ToListAsync())
                                .Concat(Consts.FixedOnlineUsers)
                                .Concat(new[] { new Guid(this.User.Identity.GetUserId()) })
                                .Distinct()
                                .ToList();

            List <UserNameDto> users = await _userService.QueryUser()
                                       .Where(u => !u.IsDeactivated)
                                       .Select(u => new UserNameDto
            {
                Name     = u.Name,
                Gender   = u.Gender,
                UserId   = u.Id,
                IsOnline = onlineUserIds.Any(i => i == u.Id)
            })
                                       .ToListAsync();

            return(Json(users, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 2
0
        public async Task <JsonResult> ProfileData(Guid id)
        {
            var authId = this.User.Identity.GetUserIdGuid();
            var user   = await _userService.QueryUser().SingleAsync(u => u.Id == id);

            if (authId != id)
            {
                await _userService.IncrementViewCount(id);
            }

            var userDto = new UserFullViewDto
            {
                AlbumPhotos = JsonConvert.DeserializeObject <List <string> >(user.AlbumPhotoUrls)
                              .Select(PhotoUrlService.GetPhotoDto).ToList(),
                Birthday     = user.Birthday,
                Description  = user.Description,
                Gender       = user.Gender,
                Interest     = user.Interest,
                Name         = user.Name,
                ProfilePhoto = PhotoUrlService.GetPhotoDto(user.ProfilePhotoUrl),
                UserId       = user.Id,
                Location     = user.Location,
                CanEdit      = authId.HasValue ? authId.Value == id : false,
                IsOnline     = _onlineUserService.GetOnlineUsers().Any(u => u.Id == user.Id)
            };

            return(Json(userDto, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 3
0
        public async Task <JsonResult> ConversationData(Guid id)
        {
            var userId = this.User.Identity.GetUserIdGuid().Value;

            var conversation = await _conversationService
                               .QueryConversation()
                               .Include(c => c.Messages)
                               .Include(c => c.Users)
                               .SingleAsync(c => c.Id == id);

            var interlocutorId = conversation.Users.First(u => u.Id != userId).Id;

            ConversationDto conversationDto = new ConversationDto
            {
                ConversationId = conversation.Id,
                Title          = conversation.Users.Single(u => u.Id != userId).Name,
                Messages       = conversation.Messages.OrderByDescending(m => m.SentOn)
                                 .Take(20)
                                 .Select(m => new MessageDto
                {
                    SentByUserId = m.SentByUserId,
                    SentOn       = m.SentOn,
                    Text         = m.Text,
                    IsSentByUser = m.SentByUserId == userId
                })
                                 .OrderBy(m => m.SentOn)
                                 .ToList(),
                Users = conversation.Users.Select(u => new UserViewDto
                {
                    Gender       = u.Gender,
                    Name         = u.Name,
                    ProfilePhoto = PhotoUrlService.GetPhotoDto(u.ProfilePhotoUrl),
                    UserId       = u.Id
                }).ToList(),
                IsInterlocutorOnline = _onlineUserService.GetOnlineUsers()
                                       .Any(u => u.Id == interlocutorId),
                InterlocutorId = interlocutorId
            };

            return(Json(conversationDto, JsonRequestBehavior.AllowGet));
        }