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)); }
private IEnumerable <GroomgyWeeklyEmail> BuildGroomgyWeeklyEmails(IEnumerable <UserWeeklyData> users) { var emails = new List <GroomgyWeeklyEmail>(); foreach (var user in users) { GroomgyWeeklyEmail weekly = new GroomgyWeeklyEmail { Email = user.Email, User = user.Name, Conversations = user.UnreadMessages.Select(m => new ConversationGroomgyWeeklyEmail { Image = PhotoUrlService.GetPhotoDto(m.Interlocutor.Photo).Small, Message = m.Text, Name = m.Interlocutor.Name }).ToArray(), Members = users.Where(u => u.Gender != user.Gender) .OrderBy(_ => new Guid()) .Take(4) .Select(u => new MemberSuggestedGroomgyWeeklyEmail { Image = PhotoUrlService.GetPhotoDto(u.Photo).Small, Url = string.Format("{0}profile/{1}", Consts.SiteUrl, u.Id) }).ToArray() }; if (weekly.Conversations.Count() == 0 && weekly.Members.Count() == 0) { continue; } emails.Add(weekly); } return(emails); }
public async Task <JsonResult> ListData(Guid id) { var userId = this.User.Identity.GetUserIdGuid(); var user = await _userService .QueryUser() .Include(u => u.ReceivedVotes) .Include(u => u.ReceivedVotes.Select(v => v.RatedByUser)) .SingleAsync(u => u.Id == id); var votes = user.ReceivedVotes .Select(v => new VoteDto { VoteId = v.Id, Comment = v.Comment, Rate = v.Rate, RatedOn = v.RatedOn, VotedByUser = new UserViewDto { Gender = v.RatedByUser.Gender, Name = v.RatedByUser.Name, ProfilePhoto = PhotoUrlService.GetPhotoDto(v.RatedByUser.ProfilePhotoUrl), UserId = v.RatedByUser.Id } }); var voteListDto = new VoteListDto { CanVote = !userId.HasValue || userId.Value != id, Votes = votes.ToList() }; return(Json(voteListDto, JsonRequestBehavior.AllowGet)); }
public async Task <JsonResult> GetMatch() { var userId = this.User.Identity.GetUserIdGuid().Value; var user = await _userService.QueryUser().SingleAsync(u => u.Id == userId); var matches = await _userService .QueryUser() .Where(u => u.Id != userId) .Where(u => u.Gender == user.Interest) .OrderBy(u => Guid.NewGuid()) .Take(2) .ToListAsync(); var dtos = matches.Select(m => new UserFullViewDto { AlbumPhotos = JsonConvert.DeserializeObject <List <string> >(m.AlbumPhotoUrls) .Select(PhotoUrlService.GetPhotoDto).ToList(), Birthday = m.Birthday, Description = m.Description, Gender = m.Gender, Name = m.Name, ProfilePhoto = PhotoUrlService.GetPhotoDto(m.ProfilePhotoUrl), UserId = m.Id, Location = m.Location }).ToList(); return(Json(dtos, JsonRequestBehavior.AllowGet)); }
public async Task <JsonResult> UploadPhotoForAlbum() { var userId = this.User.Identity.GetUserIdGuid().Value; if (this.HttpContext.Request.Files == null || this.HttpContext.Request.Files.Count == 0) { return(Json(new { success = false, errorMessage = "File not found." })); } var photo = this.HttpContext.Request.Files[0]; string fileUrl = await this.SaveFile(userId, photo.FileName, photo.InputStream); await _userService.AddAlbumPhotoUrl(userId, fileUrl); _hubContext.Clients.All .GalleryPhotoUploaded(userId, PhotoUrlService.GetPhotoDto(fileUrl)); return(Json(new { success = true })); }
public async Task <JsonResult> UploadProfilePhoto() { var userId = this.User.Identity.GetUserIdGuid().Value; var user = await _userService.QueryUser() .SingleAsync(u => u.Id == userId); if (this.HttpContext.Request.Files == null || this.HttpContext.Request.Files.Count == 0) { return(Json(new { success = false, errorMessage = "File not found." })); } var photo = this.HttpContext.Request.Files[0]; string fileUrl = await this.SaveFile(userId, "profile_" + photo.FileName, photo.InputStream); if (user.ProfilePhotoUrl != null) { var result = await _fileStorageService.DeleteFile(user.ProfilePhotoUrl); } await _userService.SetProfilePhotoUrl(userId, fileUrl); _hubContext.Clients.All .ProfilePhotoChanged(userId, PhotoUrlService.GetPhotoDto(fileUrl)); return(Json(new { success = true })); }
public async Task <JsonResult> ConversationListData() { var authUserId = this.User.Identity.GetUserIdGuid().Value; var userConversations = (await _userService .QueryUser() .Include(u => u.Conversations) .Include(u => u.Conversations.Select(c => c.Users)) .SingleAsync(u => u.Id == authUserId)) .Conversations .Where(c => !c.ConversationOptions.Single(opt => opt.UserId == authUserId).IsDeleted); List <ConversationPreviewDto> listDto = new List <ConversationPreviewDto>(); foreach (var conv in userConversations) { var user = conv.Users.First(u => u.Id != authUserId); var userDto = new UserViewDto { Gender = user.Gender, Name = user.Name, ProfilePhoto = PhotoUrlService.GetPhotoDto(user.ProfilePhotoUrl), UserId = user.Id }; var lastMessage = conv.Messages .OrderByDescending(m => m.SentOn) .Where(m => m.SentByUserId != authUserId) .FirstOrDefault(); MessageDto lastMessageDto = lastMessage != null ? new MessageDto { SentByUserId = lastMessage.SentByUserId, SentOn = lastMessage.SentOn, Text = lastMessage.Text } : null; listDto.Add(new ConversationPreviewDto { ConversationId = conv.Id, Message = lastMessageDto, User = userDto, HasNewMessages = conv .ConversationOptions .Single(u => u.UserId == authUserId) .HasNewMessages }); } return(Json(listDto, JsonRequestBehavior.AllowGet)); }
public async Task <JsonResult> Send(MessageViewModel model) { var userId = this.User.Identity.GetUserIdGuid().Value; await _conversationService.SendMessage( model.ConversationId, userId, model.SentOn, model.Text); var interlocutorUserIds = await _conversationService.QueryConversation() .Include(c => c.Users) .Where(c => c.Id == model.ConversationId) .SelectMany(c => c.Users) .Select(u => u.Id) .ToListAsync(); foreach (var id in interlocutorUserIds .Where(interlocId => interlocId != userId)) { var userDto = await _userService.QueryUser() .SingleAsync(u => u.Id == userId); _conversationHub .Clients .User(id.ToString()) .MessageReceived(model.ConversationId, new UserViewDto { Gender = userDto.Gender, Name = userDto.Name, ProfilePhoto = PhotoUrlService.GetPhotoDto(userDto.ProfilePhotoUrl), UserId = userDto.Id }, model.Text, model.SentOn); _conversationHub .Clients .User(id.ToString()) .HasNewMessages(id); } return(Json(new MessagePostedViewModel { UserId = userId, Text = model.Text, SentOn = model.SentOn })); }
private async Task <UserRankDto> ConvertToUserRankDto(UserValue userValue, string postfix) { var user = await _userService.QueryUser().SingleAsync(u => u.Id == userValue.UserId); return(new UserRankDto { Value = userValue.Value + " " + postfix, User = new UserViewDto { Gender = user.Gender, Name = user.Name, ProfilePhoto = PhotoUrlService.GetPhotoDto(user.ProfilePhotoUrl), UserId = userValue.UserId } }); }
public async Task <JsonResult> VoteForUser(VoteViewModel model) { var userId = this.User.Identity.GetUserIdGuid().Value; var voteId = Guid.NewGuid(); var latestVote = _userService.QueryUser() .Include(u => u.ReceivedVotes) .Where(u => u.Id == model.RatedOnUserId) .SelectMany(u => u.ReceivedVotes) .OrderByDescending(v => v.RatedOn) .FirstOrDefault(v => v.RatedByUserId == userId); if (latestVote != null && (model.VotedOn - latestVote.RatedOn).TotalHours < 3) { return(Json(new { success = false, error = "You can only vote every 3 hours." })); } await _voteService.Vote(voteId, model.Rate, model.Comment, userId, model.RatedOnUserId, model.VotedOn); var user = await _userService.QueryUser().SingleAsync(u => u.Id == userId); UserViewDto userView = new UserViewDto { Gender = user.Gender, Name = user.Name, ProfilePhoto = PhotoUrlService.GetPhotoDto(user.ProfilePhotoUrl), UserId = user.Id }; var ratedOnUser = await _userService.QueryUser() .SingleAsync(u => u.Id == model.RatedOnUserId); if (ratedOnUser.EmailNotificationEnabled) { await _emailService.SendVoteReceived(ratedOnUser.Email, model.RatedOnUserId, userView.Name); } _voteHub.Clients.All.VoteReceived(voteId, model.RatedOnUserId, userView, model.Rate, model.Comment, model.VotedOn); return(Json(new { success = true })); }
public async Task <JsonResult> UserTileListData(List <Guid> skipIds, int take, Gender gender) { Expression <Func <UserEntity, bool> > skipPredicate = user => true; if (skipIds != null) { skipPredicate = user => !skipIds.Contains(user.Id); } //Filter only if man or woman gender is specified Expression <Func <UserEntity, bool> > genderPredicate = user => true; if (gender != Gender.NotSpecified) { genderPredicate = user => user.Gender == gender; } var users = (await _userService.QueryUser() .Where(skipPredicate) .Where(genderPredicate) .Where(u => !u.IsDeactivated) .OrderBy(u => Guid.NewGuid()) .Take(take) .Select(u => new { Gender = u.Gender, Name = u.Name, ProfilePhotoUrl = u.ProfilePhotoUrl, UserId = u.Id, Interest = u.Interest }) .ToListAsync()) .Select(u => new UserViewDto { Gender = u.Gender, Name = u.Name, ProfilePhoto = PhotoUrlService.GetPhotoDto(u.ProfilePhotoUrl), UserId = u.UserId, Interest = u.Interest }); return(Json(users, JsonRequestBehavior.AllowGet)); }
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)); }
public async Task <JsonResult> ProfileSummaryData() { var userId = this.User.Identity.GetUserIdGuid().Value; var user = await _userService.QueryUser() .Include(u => u.Conversations.Select(c => c.ConversationOptions)) .SingleAsync(u => u.Id == userId); if (user.IsDeactivated) { HttpContext.GetOwinContext().Authentication.SignOut(); throw new ApplicationException("Account deactivated. Please contact support."); } var profileDto = new ProfileSummaryDto { Settings = new UserSettings { ShowWelcome = user.ShowWelcome }, User = new UserViewDto { Gender = user.Gender, Name = user.Name, ProfilePhoto = PhotoUrlService.GetPhotoDto(user.ProfilePhotoUrl), UserId = user.Id, Interest = user.Interest, Birthday = user.Birthday }, HasNewMessages = user.Conversations .SelectMany(c => c.ConversationOptions) .Where(opt => opt.UserId == userId) .Any(opt => opt.HasNewMessages) }; return(Json(profileDto, JsonRequestBehavior.AllowGet)); }