Exemple #1
0
        internal static List <ShallowMatchedBigLittleParentModel> GetallMatchesShallow()
        {
            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 queryDictionary = 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 <ShallowMatchedBigLittleParentModel> matches = new List <ShallowMatchedBigLittleParentModel>();
                foreach (var key in queryDictionary.Keys)
                {
                    ShallowMatchedBigLittleParentModel currentMatch = new ShallowMatchedBigLittleParentModel();
                    foreach (var match in queryDictionary[key])
                    {
                        switch (match.UserTypeId)
                        {
                        case 1:
                            currentMatch.Big = TransformHelpers.ModelToUserAccountViewModel(match);
                            break;

                        case 2:
                            currentMatch.Little = TransformHelpers.ModelToUserAccountViewModel(match);;
                            break;

                        case 3:
                            currentMatch.Parent = TransformHelpers.ModelToUserAccountViewModel(match);;
                            break;
                        }
                    }
                    currentMatch.MatchId = key.MatchId;
                    matches.Add(currentMatch);
                }
                return(matches);
            }
        }
Exemple #2
0
 public static UserAccountModel GetUserAccount(int userId)
 {
     using (var _context = new bbbsDbContext())
     {
         return(TransformHelpers.UserAccountToModel(_context.UserAccounts.FirstOrDefault(x => x.Id == userId)));
     }
 }
Exemple #3
0
 internal static void DeleteMatchById(int matchId)
 {
     using (var _context = new bbbsDbContext())
     {
         var match = _context.BigLittleParentMaps.FirstOrDefault(x => x.Id == matchId);
         _context.BigLittleParentMaps.Remove(match);
         _context.SaveChanges();
     }
 }
Exemple #4
0
 public static UserAccountModel GetUserByLogin(LoginRequestModel requestModel)
 {
     using (var _context = new bbbsDbContext())
     {
         return(TransformHelpers.UserAccountToModel(_context.UserAccounts.FirstOrDefault(
                                                        x => x.UserName == requestModel.UserName && x.Password == requestModel.Password
                                                        )));
     }
 }
Exemple #5
0
 public static UserAccountModel CreateUser(UserAccountModel userModel)
 {
     using (var _context = new bbbsDbContext())
     {
         var newUser = _context.Add(TransformHelpers.ModelToUserAccount(userModel));
         _context.SaveChanges();
         userModel.Id = newUser.Entity.Id;
         return(userModel);
     }
 }
 public static UserTypeModel CreateUserContactInfo(UserTypeModel userTypeModel)
 {
     using (var _context = new bbbsDbContext())
     {
         var newUserType = _context.Add(new UserType {
             UserTypeName = userTypeModel.UserTypeName
         });
         _context.SaveChanges();
         userTypeModel.Id = newUserType.Entity.Id;
         return(userTypeModel);
     }
 }
Exemple #7
0
 public static List <UserAccountModel> GetUserAccountsByType(int typeId)
 {
     using (var _context = new bbbsDbContext())
     {
         List <UserAccountModel> userAccountModels = new List <UserAccountModel>();
         foreach (var userAccount in _context.UserAccounts.Where(x => x.UserTypeId == typeId).ToList())
         {
             userAccountModels.Add(TransformHelpers.UserAccountToModel(userAccount));
         }
         return(userAccountModels);
     }
 }
Exemple #8
0
        public static UserAddressModel GetAddressForUser(int userAccountId)
        {
            using (var _context = new bbbsDbContext())
            {
                var userAddress = (from address in _context.UserAddresses
                                   join contactinfo in _context.ContactInfo on address.Id equals contactinfo.UserAddressId
                                   join useraccount in _context.UserAccounts on userAccountId equals useraccount.Id
                                   select address
                                   ).FirstOrDefault();

                return(TransformHelpers.ModelToAddress(userAddress));
            }
        }
 public static InterestModel CreateInterest(InterestModel interestModel)
 {
     using (var _context = new bbbsDbContext())
     {
         var newInterest = _context.Add(new Interest
         {
             InterestName = interestModel.InterestName
         });
         _context.SaveChanges();
         interestModel.Id = newInterest.Entity.Id;
         return(interestModel);
     }
 }
 public static InterestUserMapModel CreateInterestUserMap(InterestUserMapModel mapModel)
 {
     using (var _context = new bbbsDbContext())
     {
         var newMap = _context.Add(new InterestUserMap
         {
             InterestId    = mapModel.InterestId,
             UserAccountId = mapModel.UserAccountId
         });
         _context.SaveChanges();
         mapModel.Id = newMap.Entity.Id;
         return(mapModel);
     }
 }
Exemple #11
0
 public static LittleParentMapModel CreateLittleParentMap(LittleParentMapModel mapModel)
 {
     using (var _context = new bbbsDbContext())
     {
         var newMap = _context.Add(new LittleParentMap
         {
             LittleId = mapModel.LittleId,
             ParentId = mapModel.ParentId
         });
         _context.SaveChanges();
         mapModel.Id = newMap.Entity.Id;
         return(mapModel);
     }
 }
Exemple #12
0
        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);
                }
            }
        }
 public static List <UserTypeModel> GetAllUserTypes()
 {
     using (var context = new bbbsDbContext())
     {
         var modelList = new List <UserTypeModel>();
         foreach (var type in context.UserTypes)
         {
             modelList.Add(new UserTypeModel {
                 Id           = type.Id,
                 UserTypeName = type.UserTypeName
             });
         }
         return(modelList);
     }
 }
 public static ContactInfoModel CreateUserContactInfo(ContactInfoModel contactInfoModel)
 {
     using (var _context = new bbbsDbContext())
     {
         var newContactInfo = _context.Add(new ContactInfo
         {
             Email         = contactInfoModel.Email,
             PhoneNumber   = contactInfoModel.PhoneNumber,
             UserAccountId = contactInfoModel.UserAccountId,
             UserAddressId = contactInfoModel.UserAddressId
         });
         _context.SaveChanges();
         contactInfoModel.Id = newContactInfo.Entity.Id;
         return(contactInfoModel);
     }
 }
Exemple #15
0
 public static UserAddressModel CreateUserAddress(UserAddressModel addressModel)
 {
     using (var _context = new bbbsDbContext())
     {
         var newAddress = _context.Add(new UserAddress
         {
             City        = addressModel.City,
             Zip         = addressModel.Zip,
             StreetLine1 = addressModel.StreetLine1,
             StreetLine2 = addressModel.StreetLine2,
             State       = addressModel.State
         });
         _context.SaveChanges();
         addressModel.Id = newAddress.Entity.Id;
         return(addressModel);
     }
 }
Exemple #16
0
        public static List <UserAccountModel> FindUnmatchedBigs()
        {
            using (var _context = new bbbsDbContext())
            {
                var matchedBigUserAccounts = (from ua in _context.UserAccounts
                                              join blpm in _context.BigLittleParentMaps on ua.Id equals blpm.BigId
                                              select ua).Distinct().ToList();

                var unmatchedBigUserAccounts = (from ua in _context.UserAccounts
                                                where !matchedBigUserAccounts.Contains(ua) && ua.UserTypeId == 1
                                                select ua).Distinct().ToList();

                var unmatchedBigUserAccountModels = TransformHelpers.ListUserAccountToModel(unmatchedBigUserAccounts);

                return(unmatchedBigUserAccountModels);
            }
        }
        public static ContactInfoModel UpdateUserContactInfo(ContactInfoModel contactInfoModel)
        {
            using (var _context = new bbbsDbContext())
            {
                var existingContactInfo = _context.ContactInfo.FirstOrDefault(x => x.Id == contactInfoModel.Id);

                if (existingContactInfo != null)
                {
                    existingContactInfo.Email         = contactInfoModel.Email;
                    existingContactInfo.PhoneNumber   = contactInfoModel.PhoneNumber;
                    existingContactInfo.UserAccountId = existingContactInfo.UserAccountId;
                    existingContactInfo.UserAddressId = existingContactInfo.UserAddressId;
                    _context.SaveChanges();
                    return(contactInfoModel);
                }
            }
            return(null);
        }
 public static ContactInfoModel GetUserContactInfo(int userId)
 {
     using (var _context = new bbbsDbContext())
     {
         var query = _context.ContactInfo.FirstOrDefault(x => x.UserAccountId == userId);
         if (query == null)
         {
             return(null);
         }
         return(new ContactInfoModel
         {
             Id = query.Id,
             UserAddressId = query.UserAddressId,
             Email = query.Email,
             PhoneNumber = query.PhoneNumber,
             UserAccountId = query.UserAccountId
         });
     }
 }
Exemple #19
0
        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));
            }
        }
Exemple #20
0
        public static UserAccountModel UpdateUserAccount(UserAccountModel userModel)
        {
            using (var _context = new bbbsDbContext())
            {
                var existingUser = _context.UserAccounts.FirstOrDefault(x => x.Id == userModel.Id);

                if (existingUser != null)
                {
                    existingUser.FirstName  = userModel.FirstName;
                    existingUser.LastName   = userModel.LastName;
                    existingUser.UserName   = userModel.UserName;
                    existingUser.UserTypeId = userModel.UserTypeId;
                    existingUser.Age        = userModel.Age;
                    _context.SaveChanges();
                    return(TransformHelpers.UserAccountToModel(existingUser));
                }
            }
            return(null);
        }
Exemple #21
0
        public static UserAddressModel UpdateUserAddress(UserAddressModel userAddressModel)
        {
            using (var _context = new bbbsDbContext())
            {
                var existingUserAddress = _context.UserAddresses.FirstOrDefault(x => x.Id == userAddressModel.Id);

                if (existingUserAddress != null)
                {
                    existingUserAddress.StreetLine1 = userAddressModel.StreetLine1;
                    existingUserAddress.StreetLine2 = userAddressModel.StreetLine2;
                    existingUserAddress.City        = userAddressModel.City;
                    existingUserAddress.State       = userAddressModel.State;
                    existingUserAddress.Zip         = userAddressModel.Zip;
                    _context.SaveChanges();
                    return(userAddressModel);
                }
            }
            return(null);
        }
Exemple #22
0
        public static ConsolidatedUserInformationResponseModel FindParentForLittle(int littleId)
        {
            using (var _context = new bbbsDbContext())
            {
                var mapping = (from lpm in _context.LittleParentMaps
                               where lpm.LittleId == littleId
                               select lpm).FirstOrDefault();
                UserAccount parentAccount = null;
                if (mapping != null)
                {
                    parentAccount = _context.UserAccounts.FirstOrDefault(x => x.Id == mapping.ParentId);
                }
                ConsolidatedUserInformationResponseModel uam = null;
                if (parentAccount != null)
                {
                    uam = TransformHelpers.UserAccountToConsResModel(parentAccount);
                }

                return(uam);
            }
        }
Exemple #23
0
        public static UserAddressModel GetAddress(int addressId)
        {
            using (var _context = new bbbsDbContext())
            {
                var query = _context.UserAddresses.FirstOrDefault(x => x.Id == addressId);

                if (query == null)
                {
                    return(null);
                }
                return(new UserAddressModel
                {
                    City = query.City,
                    Id = query.Id,
                    State = query.State,
                    StreetLine1 = query.StreetLine1,
                    StreetLine2 = query.StreetLine2,
                    Zip = query.Zip
                });
            }
        }
Exemple #24
0
        public static BigLittleParentMapModel CreateBigLittleParentMapModel(BigLittleParentMapModel mapModel)
        {
            using (var _context = new bbbsDbContext())
            {
                int parentId = FindParentForLittle(mapModel.LittleId).user.Id;

                var parentLittleMatch = (from lpm in _context.LittleParentMaps
                                         where lpm.LittleId == mapModel.LittleId &&
                                         lpm.ParentId == parentId
                                         select lpm).FirstOrDefault();

                var newMap = _context.Add(new BigLittleParentMap
                {
                    BigId             = mapModel.BigId,
                    LittleParentMapId = parentLittleMatch.Id,
                });
                _context.SaveChanges();
                mapModel.MatchId = newMap.Entity.Id;
                return(mapModel);
            }
        }
        public static List <InterestModel> GetUserInterests(int userId)
        {
            using (var _context = new bbbsDbContext())
            {
                var interests = (from Interest i in _context.Interests
                                 join ium in _context.InterestUserMaps on i.Id equals ium.InterestId
                                 join ua in _context.UserAccounts on ium.UserAccountId equals ua.Id
                                 where ua.Id == userId
                                 select i).Distinct().ToList();

                List <InterestModel> interestModels = new List <InterestModel>();
                foreach (var interest in interests)
                {
                    interestModels.Add(new InterestModel
                    {
                        Id           = interest.Id,
                        InterestName = interest.InterestName
                    });
                }
                return(interestModels);
            }
        }
Exemple #26
0
        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);
            }
        }