/// <summary>
        /// FindByIdAsync
        /// </summary>
        /// <param name="generalUserId"></param>
        /// <param name="user"></param>
        /// <returns></returns>
        public async Task <IGeneralUser> FindByIdAsync(int generalUserId, ClaimsPrincipal user)
        {
            var appUserId   = _userManager.GetUserId(user);
            var generalUser = _dbContext.GeneralUsers
                              .Include(g => g.Identity)
                              .Include(g => g.City)
                              .Include(g => g.GeneralUserTeachingAgeGroups)
                              .ThenInclude(t => t.TeachingAgeGroup)
                              .Include(g => g.GeneralUserTeachingSubjects)
                              .ThenInclude(t => t.TeachingSubject)
                              .Include(g => g.GeneralUserTeachingLevels)
                              .ThenInclude(t => t.TeachingLevel)
                              .Include(g => g.GeneralUserInterests)
                              .ThenInclude(t => t.Interest)
                              .FirstOrDefault(g => g.Id == generalUserId);

            IGeneralUser IGeneralUser = await Task.FromResult(_mapper.Map <GeneralUser, IGeneralUser>(generalUser));

            // Make call to AWS S3 to see if any profile image is linked to this GeneralUser
            if (IGeneralUser != null)
            {
                IImage profileImage = await _awsS3Service.GetProfileImageByUserAsync(IGeneralUser.IdentityId);

                if (profileImage != null)
                {
                    IGeneralUser.ProfileImage = profileImage;
                }
            }

            return(IGeneralUser);
        }
Beispiel #2
0
        public async Task <IEnumerable <IGeneralUser> > GetMatchedBuddiesAsync(int userId)
        {
            IEnumerable <GeneralUser> buddies = _databaseContext.BuddyRequests
                                                .Where(buddy =>
                                                       (buddy.ReceivingGeneralUserId == userId || buddy.RequestingGeneralUserId == userId) &&
                                                       buddy.RequestState == BuddyRequestState.Matched
                                                       )
                                                .Select(x => (userId == x.RequestingGeneralUserId) ? x.ReceivingGeneralUser : x.RequestingGeneralUser)
                                                // Include all related data of ReceivingGeneralUser
                                                .ToList();

            IEnumerable <IGeneralUser> generalUsers = _databaseContext.GeneralUsers
                                                      .Where(g => buddies.Contains(g))
                                                      // Include all related data of RequestingGeneralUser
                                                      .Include(g => g.Identity)
                                                      .Include(g => g.City)
                                                      .Include(g => g.GeneralUserTeachingAgeGroups)
                                                      .ThenInclude(t => t.TeachingAgeGroup)
                                                      .Include(g => g.GeneralUserTeachingSubjects)
                                                      .ThenInclude(t => t.TeachingSubject)
                                                      .Include(g => g.GeneralUserTeachingLevels)
                                                      .ThenInclude(t => t.TeachingLevel)
                                                      .Include(g => g.GeneralUserInterests)
                                                      .ThenInclude(t => t.Interest)
                                                      .Include(g => g.Links)
                                                      .ThenInclude(l => l.LinkInterests)
                                                      .ThenInclude(l => l.Interest)
                                                      .OrderBy(g => g.Identity.FirstName)
                                                      .Select(g => _mapper.Map <IGeneralUser>(g))
                                                      .ToList();

            // Make call to AWS S3 to see if any profile image is linked to this GeneralUser
            foreach (IGeneralUser generalUser in generalUsers)
            {
                IImage profileImage = await _awsS3Service.GetProfileImageByUserAsync(generalUser.IdentityId);

                if (profileImage != null)
                {
                    generalUser.ProfileImage = profileImage;
                }

                foreach (ILink link in generalUser.Links)
                {
                    link.Image = await LoadLinkImage(link);
                }
            }

            return(await Task.FromResult(generalUsers));
        }
        public async Task <IEnumerable <ILink> > GetFavoriteLinksByUserAsync(IGeneralUser generalUser)
        {
            IEnumerable <Link> favoriteLinks = _dbContext.FavoriteLinks
                                               .Where(fl =>
                                                      fl.GeneralUserId == generalUser.Id
                                                      )
                                               .Select(fl => fl.Link)
                                               // Include all related data of ReceivingGeneralUser
                                               .ToList();

            IEnumerable <ILink> links = _dbContext.Links
                                        .Where(
                l => favoriteLinks.Contains(l) &&
                l.IsDeleted == false
                )
                                        // Include all related data of RequestingGeneralUser
                                        .Include(l => l.GeneralUser)
                                        .ThenInclude(g => g.Identity)
                                        .Include(l => l.GeneralUser.City)
                                        .Include(l => l.GeneralUser.GeneralUserTeachingAgeGroups)
                                        .ThenInclude(g => g.TeachingAgeGroup)
                                        .Include(l => l.GeneralUser.GeneralUserTeachingSubjects)
                                        .ThenInclude(g => g.TeachingSubject)
                                        .Include(l => l.GeneralUser.GeneralUserTeachingLevels)
                                        .ThenInclude(g => g.TeachingLevel)
                                        .Include(l => l.GeneralUser.GeneralUserInterests)
                                        .ThenInclude(g => g.Interest)
                                        .Include(l => l.LinkInterests)
                                        .ThenInclude(l => l.Interest)
                                        .Select(l => _mapper.Map <ILink>(l))
                                        .ToList();

            // Make call to AWS S3 to see if any profile image is linked to this GeneralUser
            foreach (ILink link in links)
            {
                link.Image = await LoadLinkImage(link);

                // Make call to AWS S3 to see if any profile image is linked to the GeneralUser of this link
                IImage profileImage = await _awsS3Service.GetProfileImageByUserAsync(link.GeneralUser.IdentityId);

                if (profileImage != null)
                {
                    link.GeneralUser.ProfileImage = profileImage;
                }
            }

            return(await Task.FromResult(links));
        }