internal static MatchedBigLittleParentModel GetMatch(int matchId) { using (var _context = new bbbsDbContext()) { MatchedBigLittleParentModel matchedBLPM = new MatchedBigLittleParentModel(); var matchedUsers = (from ua in _context.UserAccounts from lpm in _context.LittleParentMaps from blpm in _context.BigLittleParentMaps where lpm.Id == blpm.LittleParentMapId && ((blpm.Id == matchId) && (ua.Id == lpm.LittleId || ua.Id == lpm.ParentId || ua.Id == blpm.BigId)) select ua).Distinct().ToList(); if (matchedUsers != null) { matchedBLPM.MatchId = matchId; foreach (var match in matchedUsers) { var newModel = new ConsolidatedUserInformationResponseModel(); newModel.user = TransformHelpers.ModelToUserAccountViewModel(UserAccountService.GetUserAccount(match.Id)); newModel.address = AddressService.GetAddressForUser(match.Id); newModel.contactInfo.UserAddressId = newModel.address.Id; newModel.contactInfo = ContactInfoService.GetUserContactInfo(match.Id); newModel.interests = InterestService.GetUserInterests(match.Id); switch (match.UserTypeId) { case 1: matchedBLPM.Big = newModel; break; case 2: matchedBLPM.Little = newModel; break; case 3: matchedBLPM.Parent = newModel; break; } } matchedBLPM.sharedInterests = InterestService.GetSharedInterest(matchedBLPM.Big.user.Id, matchedBLPM.Little.user.Id).ToList(); return(matchedBLPM); } else { return(null); } } }
internal static MatchedBigLittleParentModel GetMatchByUserAccountId(int userId) { using (var _context = new bbbsDbContext()) { MatchedBigLittleParentModel matchedBLPM = new MatchedBigLittleParentModel(); var match = (from blpm in _context.BigLittleParentMaps join lpm in _context.LittleParentMaps on blpm.LittleParentMapId equals lpm.Id where blpm.BigId == userId || lpm.LittleId == userId select blpm ).FirstOrDefault(); if (match == null) { return(null); } return(GetMatch(match.Id)); } }
internal static List <MatchedBigLittleParentModel> GetAllMatches() { using (var _context = new bbbsDbContext()) { var query = (from blpm in _context.BigLittleParentMaps join lpm in _context.LittleParentMaps on blpm.LittleParentMapId equals lpm.Id from ua in _context.UserAccounts where blpm.BigId == ua.Id || lpm.LittleId == ua.Id || lpm.ParentId == ua.Id select new UserAccountWithMatchId { MatchId = blpm.Id, FirstName = ua.FirstName, LastName = ua.LastName, Id = ua.Id, Password = ua.Password, UserName = ua.UserName, UserTypeId = ua.UserTypeId, Age = ua.Age }) .Distinct().ToList(); var matchesQuery = query.GroupBy(key => new { key.MatchId }, model => new UserAccountModel { Id = model.Id, FirstName = model.FirstName, LastName = model.LastName, UserName = model.UserName, UserTypeId = model.UserTypeId, Password = model.Password, Age = model.Age, PictureUrl = model.PictureUrl }).ToDictionary(y => y.Key, z => z.ToList()); List <MatchedBigLittleParentModel> matches = new List <MatchedBigLittleParentModel>(); foreach (var key in matchesQuery.Keys) { MatchedBigLittleParentModel currentMatch = new MatchedBigLittleParentModel(); foreach (var match in matchesQuery[key]) { var newModel = new ConsolidatedUserInformationResponseModel(); newModel.user = TransformHelpers.ModelToUserAccountViewModel(UserAccountService.GetUserAccount(match.Id)); newModel.address = AddressService.GetAddressForUser(match.Id); newModel.contactInfo.UserAddressId = newModel.address.Id; newModel.contactInfo = ContactInfoService.GetUserContactInfo(match.Id); newModel.interests = InterestService.GetUserInterests(match.Id); switch (match.UserTypeId) { case 1: currentMatch.Big = newModel; break; case 2: currentMatch.Little = newModel; break; case 3: currentMatch.Parent = newModel; break; } } currentMatch.sharedInterests = InterestService.GetSharedInterest(currentMatch.Big.user.Id, currentMatch.Little.user.Id).ToList(); currentMatch.MatchId = key.MatchId; matches.Add(currentMatch); } return(matches); } }