Example #1
1
        //adds a new country to the database if it is not already in it
        public static void createLand(string land)
        {
            using (DBEntities dbConnection = new DBEntities())
            {
                List<Land> foundLand = dbConnection.Land.Where(x => x.landName.Equals(land)).ToList();
                if (foundLand.Count > 0)
                {

                }
                else
                {
                    Land newLand = new Land();
                    newLand.landName = land;
                    dbConnection.Land.Add(newLand);
                    dbConnection.SaveChanges();
                }
            }
        }
Example #2
0
        //Returns a List of Members next to the memberID based on the maximum distance
        public static List<DistancedMember> doDistanceSearch(double distance, Int64 mitgliedID)
        {
            List<DistancedMember> ratedMembers = new List<DistancedMember>();
            using (DBEntities dbConnection = new DBEntities())
            {
                List<Nullable<Int64>> allMitglieder = dbConnection.getNotFriends(mitgliedID).ToList();

                foreach (Int64 currentMitglied in allMitglieder)
                {
                    double distanceCurrentUser = GeoCalculator.calculateDistanceBetweenUsers(mitgliedID, currentMitglied);
                    if(distanceCurrentUser != -1)
                    {
                        if (distanceCurrentUser <= distance)
                        {
                            Mitglied currentMitgliedObject = Datareader.getMitgliedByID(currentMitglied);
                            ratedMembers.Add(new DistancedMember(currentMitgliedObject, distanceCurrentUser));
                        }
                        else
                        {
                        }
                    }
                    else
                    {

                    }
                }

                return ratedMembers.OrderBy(x => x.distance).ToList();
            }
        }
Example #3
0
 //6. gives Rating for common friends with a stranger
 public static List<Ratedmember> checkCommonFriendsWithStranger(List<Ratedmember> ratedMembers, Int64 mitgliedID, List<Nullable<long>> myFriends)
 {
     int ratingUP = 3;
     using (DBEntities dbConnection = new DBEntities())
     {
         Mitglied currentMitglied = dbConnection.Mitglied.Find(mitgliedID);
         foreach (Ratedmember currentRated in ratedMembers)
         {
             //List<Mitglied> stangersFriends = Friendsuggestor.getMyFriends(currentRated.mitgliedData.mitgliedID);
             ObjectResult<Nullable<long>> strangersFriends = dbConnection.getMyFriendsSP(currentRated.mitgliedData.mitgliedID);
             foreach (Int64 currentStrangersFriend in strangersFriends)
             {
                 bool foundCommonFriend = false;
                 foreach (long currentUsersFriend in myFriends)
                 {
                     if (currentUsersFriend.Equals(currentStrangersFriend))
                     {
                         foundCommonFriend = true;
                     }
                     else
                     {
                     }
                 }
                 if (foundCommonFriend == true)
                 {
                     ratedMembers.Find(x => x.Equals(currentRated)).incrementRating(ratingUP);
                 }
                 else { }
             }
         }
     }
     return ratedMembers;
 }
Example #4
0
 public static Boolean checkIfUserExists(string vorname, string nachname, string email)
 {
     using (DBEntities dbConnection = new DBEntities())
     {
         try
         {
             if (dbConnection.Mitglied.Where(x => x.mitgliedEmail.Equals(email)).Count() != 0)
             {
                 return true;
             }
             else if (dbConnection.Mitglied.Where(x => x.mitgliedNachname.Equals(nachname)).Where(x => x.mitgliedVorname.Equals(vorname)).Count() != 0)
             {
                 return true;
             }
             else
             {
                 return false;
             }
         }
         catch
         {
             return false;
         }
     }
 }
Example #5
0
        //returns true if the logininformation is correct, false if not
        public static bool checkLogin(string email, string password)
        {
            using (DBEntities dbCon = new DBEntities())
            {
                try
                {
                    string dbHashvalue = dbCon.Mitglied.Where(x => x.mitgliedEmail.Equals(email)).Single().Passwords.passwordName;
                    string dbSalt = dbCon.Mitglied.Where(x => x.mitgliedEmail.Equals(email)).Single().Passwords.passwordSalt;
                    Int64 userID = dbCon.Mitglied.Where(x => x.mitgliedEmail.Equals(email)).Single().mitgliedID;
                    string calculatedHash = Hasher.HashPassword(password, dbSalt, SHA512.Create());

                    if (calculatedHash == dbHashvalue)
                    {
                        return true;
                    }
                    else
                    {
                        return false;
                    }
                }
                catch (Exception e)
                {
                    return false;
                }
            }
        }
Example #6
0
        //calculates the distance between two specific users
        public static double calculateDistanceBetweenUsers(Int64 currentUserID, Int64 otherUser)
        {
            using (DBEntities dbConnection = new DBEntities())
            {
                Mitglied a = dbConnection.Mitglied.Find(currentUserID);
                Mitglied b = dbConnection.Mitglied.Find(otherUser);
                //checks if the two users have a city and there are coordinates for that city
                if (!a.stadtID.Equals(null) && !b.stadtID.Equals(null))
                {
                    if (a.Stadt.stadtLon != null && a.Stadt.stadtLat != null && b.Stadt.stadtLat != null && b.Stadt.stadtLon != null)
                    {
                        double sLat = double.Parse(a.Stadt.stadtLat.ToString());
                        double sLon = double.Parse(a.Stadt.stadtLon.ToString());
                        double eLat = double.Parse(b.Stadt.stadtLat.ToString());
                        double eLon = double.Parse(b.Stadt.stadtLon.ToString());

                        return calculateDistance(sLat, sLon, eLat, eLon);
                    }
                    else
                    {
                        return -1;
                    }
                }
                else
                {
                    return -1;
                }
            }
        }
Example #7
0
 //changes the Company of a specific user
 public static void changeArbeitgeber(Int64 mitgliedID, string arbeitgeber)
 {
     using (DBEntities dbConnection = new DBEntities())
     {
         dbConnection.Mitglied.Find(mitgliedID).mitgliedArbeitgeber = arbeitgeber;
         dbConnection.SaveChanges();
     }
 }
Example #8
0
 //changes the Job of a specific user
 public static void changeJob(Int64 mitgliedID, string jobname)
 {
     using (DBEntities dbConnection = new DBEntities())
     {
         dbConnection.Mitglied.Find(mitgliedID).mitgliedJob = jobname;
         dbConnection.SaveChanges();
     }
 }
Example #9
0
 //changes the Phonenumber of a specific user
 public static void changeMobileNbr(Int64 mitgliedID, string mobileNbr)
 {
     using (DBEntities dbConnection = new DBEntities())
     {
         dbConnection.Mitglied.Find(mitgliedID).mitgliedMobil = mobileNbr;
         dbConnection.SaveChanges();
     }
 }
Example #10
0
 //creates a entry in the Logfile (DO NOT USE ON LIVESYSTEM)
 public static void createLogEntry(string ntName, string ip, Int64 mitgliedID)
 {
     using (DBEntities dbConnection = new DBEntities())
     {
         dbConnection.LoginLog.Add(new LoginLog(ntName, ip, mitgliedID));
         dbConnection.SaveChanges();
     }
 }
Example #11
0
 //changes the city of a specific user
 public static void changeStadt(Int64 mitgliedID, string stadt)
 {
     using (DBEntities dbConnection = new DBEntities())
     {
         List<Stadt> foundStadt = dbConnection.Stadt.Where(x => x.stadtName.Equals(stadt)).ToList();
         dbConnection.Mitglied.Find(mitgliedID).stadtID = foundStadt.First().stadtID;
         dbConnection.SaveChanges();
     }
 }
Example #12
0
 //accepts a specific friendrequest
 public static void acceptFriendship(Int64 anfrageID)
 {
     using (DBEntities dbConnection = new DBEntities())
     {
         dbConnection.Freundschaftsanfrage.Find(anfrageID).freundschaftsanfrageAngenommen = true;
         Int64 a = dbConnection.Freundschaftsanfrage.Find(anfrageID).mitgliedIDSender;
         Int64 b = dbConnection.Freundschaftsanfrage.Find(anfrageID).mitgliedIDEmpfaenger;
         dbConnection.Freundschaft.Add(new Freundschaft(a, b, true));
         dbConnection.SaveChanges();
     }
 }
Example #13
0
 public static List<string> getAllHobbies()
 {
     using (DBEntities dbConnection = new DBEntities())
     {
         List<string> allHobbies = new List<string>();
         allHobbies.Add("");
         foreach(Hobby a in dbConnection.Hobby)
         {
             allHobbies.Add(a.hobbyName);
         }
         return allHobbies;
     }
 }
Example #14
0
 public static List<string> getAllBeziehungen()
 {
     using (DBEntities dbConnection = new DBEntities())
     {
         List<Beziehungsstatus> allBez = dbConnection.Beziehungsstatus.ToList();
         List<string> allBeziehungen = new List<string>();
         allBeziehungen.Add("");
         foreach (Beziehungsstatus a in allBez)
         {
             allBeziehungen.Add(a.beziehungsstatusName);
         }
         return allBeziehungen;
     }
 }
Example #15
0
        public static List<string> getAllLaender()
        {
            using(DBEntities dbConnection = new DBEntities())
            {
                List<string> laender =new List<string>();
                laender.Add("");
                foreach (Land a in dbConnection.Land)
                {
                    laender.Add(a.landName);
                }

                return laender;
            }
        }
Example #16
0
 //returns true/false if two users are already friends or not
 public static bool checkIfAlreadyFriends(Int64 mitgliedA, Int64 mitgliedB)
 {
     using (DBEntities dbConnection = new DBEntities())
     {
         int x = dbConnection.checkFriendship(mitgliedA, mitgliedB).First().Value;
         if (x >= 1)
         {
             return false;
         }
         else
         {
             return true;
         }
     }
 }
Example #17
0
 //changes the Relationship of a specific user
 public static void changeBeziehung(Int64 mitgliedID, string beziehung)
 {
     using (DBEntities dbConnection = new DBEntities())
     {
         List<Beziehungsstatus> foundBeziehungsstatus = dbConnection.Beziehungsstatus.Where(x => x.beziehungsstatusName.Equals(beziehung)).ToList();
         if (foundBeziehungsstatus.Count > 0)
         {
             dbConnection.Mitglied.Find(mitgliedID).beziehungsstatusID = foundBeziehungsstatus.First().beziehungsstatusID;
             dbConnection.SaveChanges();
         }
         else
         {
             Beziehungsstatus myNewBez = new Beziehungsstatus(beziehung);
             myNewBez.beziehungsstatusName = beziehung;
             dbConnection.Beziehungsstatus.Add(myNewBez);
             dbConnection.SaveChanges();
             dbConnection.Mitglied.Find(mitgliedID).beziehungsstatusID = myNewBez.beziehungsstatusID;
             dbConnection.SaveChanges();
         }
     }
 }
Example #18
0
 //5. gives Rating regarding the same Hobbies
 public static List<Ratedmember> checkHobbies(List<Ratedmember> ratedMembers, Int64 mitgliedID)
 {
     int ratingUP = 2;
     using (DBEntities dbConnection = new DBEntities())
     {
         Mitglied currentMitglied = dbConnection.Mitglied.Find(mitgliedID);
         List<Hobby_Mitglied> currentMitgliedHobbies = currentMitglied.Hobby_Mitglied.ToList();
         if (currentMitgliedHobbies != null)
         {
             Mitglied ratedMitglied = new Mitglied();
             List<Hobby_Mitglied> currentRatedMitgliedHobbies = new List<Hobby_Mitglied>();
             foreach (Ratedmember currentMemberToRate in ratedMembers)
             {
                 ratedMitglied = dbConnection.Mitglied.Find(currentMemberToRate.mitgliedData.mitgliedID);
                 currentRatedMitgliedHobbies = ratedMitglied.Hobby_Mitglied.ToList();
                 if (currentRatedMitgliedHobbies != null)
                 {
                     foreach (Hobby_Mitglied currentHobby in currentMitgliedHobbies)
                     {
                         foreach (Hobby_Mitglied currentRatedMitgliedHobby in currentRatedMitgliedHobbies)
                         {
                             if (currentHobby.hobbyID.Equals(currentRatedMitgliedHobby.hobbyID))
                             {
                                 ratedMembers.Find(x => x.Equals(currentMemberToRate)).incrementRating(ratingUP);
                             }
                             else { }
                         }
                     }
                 }
                 else { }
             }
         }
         else { }
     }
     return ratedMembers;
 }
Example #19
0
 //uploads a new profile picture in the database
 public static void uploadProfilePic(Int64 mitgliedID, Byte[] pic)
 {
     using (DBEntities dbConnection = new DBEntities())
     {
         dbConnection.Mitglied.Find(mitgliedID).mitgliedProfilbild = pic;
         dbConnection.SaveChanges();
     }
 }
Example #20
0
 //creates a new message sent from an user to an other
 public static void sendNewMessageToUser(string betreff, string nachricht, Int64 senderID, Int64 empfID)
 {
     using (DBEntities dbConnection = new DBEntities())
     {
         Nachricht newNachricht = new Nachricht(betreff, nachricht, senderID, empfID);
         dbConnection.Nachricht.Add(newNachricht);
         dbConnection.SaveChanges();
     }
 }
Example #21
0
        //creates a new friendrequest
        public static void createFA(Int64 senderID, Int64 empfID)
        {
            using (DBEntities dbConnection = new DBEntities())
            {
                Freundschaftsanfrage newFA = new Freundschaftsanfrage(senderID, empfID, false);
                dbConnection.Freundschaftsanfrage.Add(newFA);
                dbConnection.SaveChanges();

                Int64 id = newFA.freundschaftsanfrageID;
                String nachricht = id.ToString();
                dbConnection.Nachricht.Add(new Nachricht("Neue Anfrage", nachricht, senderID, empfID));
                dbConnection.SaveChanges();
            }
        }
Example #22
0
 //creates a university in the database if it is not already in it
 public static void createUni(string uniName, string stadtName)
 {
     using (DBEntities dbConnection = new DBEntities())
     {
         List<Stadt> foundStadt = dbConnection.Stadt.Where(x => x.stadtName.Equals(stadtName)).ToList();
         if (foundStadt.Count > 0)
         {
             Universitaet newUni = new Universitaet();
             newUni.uniName = uniName;
             newUni.stadtID = foundStadt.First().stadtID;
             dbConnection.Universitaet.Add(newUni);
             dbConnection.SaveChanges();
         }
         else
         {
         }
     }
 }
Example #23
0
 //adds a new Studiengang to the database if not already in it
 public static void createStudiengang(string studiengang)
 {
     using (DBEntities dbConnection = new DBEntities())
     {
         List<Studiengang> foundStudiengang = dbConnection.Studiengang.Where(x => x.studiengangName.Equals(studiengang)).ToList();
         if (foundStudiengang.Count > 0)
         {
         }
         else
         {
             Studiengang newStudiengang = new Studiengang();
             newStudiengang.studiengangName = studiengang;
             dbConnection.Studiengang.Add(newStudiengang);
             dbConnection.SaveChanges();
         }
     }
 }
Example #24
0
 //creates a new newsfeedentry
 public static void createStatus(string text, Int64 mitgliedID)
 {
     using (DBEntities dbConnection = new DBEntities())
     {
         Statusmeldung newStatus = new Statusmeldung(text, mitgliedID);
         dbConnection.Statusmeldung.Add(newStatus);
         dbConnection.SaveChanges();
     }
 }
Example #25
0
        //creates a new city in the database if it is not already in it
        public static void createStadt(string stadt, int plz, string land)
        {
            using (DBEntities dbConnection = new DBEntities())
            {
                List<Land> foundLand = dbConnection.Land.Where(x => x.landName.Equals(land)).ToList();
                int landID;
                Land newLand = new Land();

                if (foundLand.Count > 0)
                {
                    landID = foundLand.First().landID;
                }
                else
                {
                    newLand.landName = land;
                    dbConnection.Land.Add(newLand);
                    dbConnection.SaveChanges();
                    landID = newLand.landID;
                }

                List<Stadt> foundStadt = dbConnection.Stadt.Where(x => x.stadtName.Equals(stadt)).ToList();
                Stadt newStadt = new Stadt();

                if (foundStadt.Count > 0)
                {
                }
                else
                {
                    newStadt.stadtName = stadt;
                    newStadt.stadtPLZ = plz;
                    newStadt.landID = landID;
                    dbConnection.Stadt.Add(newStadt);
                    dbConnection.SaveChanges();
                }
            }
        }
Example #26
0
        //creates a new user
        public static void createNewUser(string vorname, string nachname, DateTime gebdatum, string email, string pw, Nullable<bool> geschlecht)
        {
            using (DBEntities dbConnection = new DBEntities())
            {
                string username = email;
                string clearPW = pw;
                //create Hashed PW
                string salt = Hasher.GenerateSaltValue();
                string hashedPW = Hasher.HashPassword(clearPW, salt, SHA512.Create());

                //enters the PW in the specific table
                Passwords newPW = new Passwords();
                newPW.passwordName = hashedPW;
                newPW.passwordSalt = salt;

                dbConnection.Passwords.Add(newPW);
                dbConnection.SaveChanges();

                //adds the new user
                Mitglied newMitglied = new Mitglied(vorname, nachname, gebdatum, email, newPW.passwordID, geschlecht);

                dbConnection.Mitglied.Add(newMitglied);

                dbConnection.SaveChanges();

            }
        }
Example #27
0
 //changes the Studienjahrgang of a specific user
 public static void changeStudienjahrgang(Int64 mitgliedID, int studienJahrgang)
 {
     using (DBEntities dbConnection = new DBEntities())
     {
         dbConnection.Mitglied.Find(mitgliedID).mitgliedStudienjahrgang = studienJahrgang;
         dbConnection.SaveChanges();
     }
 }
Example #28
0
 //adds a new hobby to a user and if neccessary to the database
 public static void enterHobby(Int64 currentUser, string hobby)
 {
     using (DBEntities dbConnection = new DBEntities())
     {
         List<Hobby> foundHobbies = dbConnection.Hobby.Where(x => x.hobbyName.Equals(hobby)).ToList();
         if (foundHobbies.Count > 0)
         {
             Hobby_Mitglied newHobbyMitglied = new Hobby_Mitglied(currentUser, foundHobbies.First().hobbyID);
             dbConnection.Hobby_Mitglied.Add(newHobbyMitglied);
             dbConnection.SaveChanges();
             //zuweisen
         }
         else
         {
             Hobby newHobby = new Hobby(hobby);
             dbConnection.Hobby.Add(newHobby);
             dbConnection.SaveChanges();
             dbConnection.Hobby_Mitglied.Add(new Hobby_Mitglied(currentUser, newHobby.hobbyID));
             dbConnection.SaveChanges();
             //anlegen
         }
     }
 }
Example #29
0
 //changes the Studiengang of a specific user
 public static void changeStudiengang(Int64 mitgliedID, string studiengang)
 {
     using (DBEntities dbConnection = new DBEntities())
     {
         List<Studiengang> foundStudiengang = dbConnection.Studiengang.Where(x => x.studiengangName.Equals(studiengang)).ToList();
         //if (foundStudiengang.Count > 1)
         //{
             dbConnection.Mitglied.Find(mitgliedID).studiengangID = foundStudiengang.First().studiengangID;
             dbConnection.SaveChanges();
         //}
         //else
         //{
         //    Studiengang newStudiengang = new Studiengang();
         //    newStudiengang.studiengangName = studiengang;
         //    dbConnection.Studiengang.Add(newStudiengang);
         //    dbConnection.SaveChanges();
         //}
     }
 }
Example #30
0
 //changes the university of a member
 public static void changeUni(Int64 mitgliedID, string uniName)
 {
     using (DBEntities dbConnection = new DBEntities())
     {
         List<Universitaet> foundUni = dbConnection.Universitaet.Where(x => x.uniName.Equals(uniName)).ToList();
         dbConnection.Mitglied.Find(mitgliedID).uniID = foundUni.First().uniID;
         dbConnection.SaveChanges();
     }
 }