//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(); } } }
//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(); } }
//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(); } }
//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(); } }
//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(); } }
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(); } }
//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(); } }
//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(); } } }
//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 } } }
//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 { } } }
//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(); } } }
//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(); } }
//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(); } }
//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(); } }
//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(); } }
//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(); } }
//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(); } }
//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(); } } }
//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(); } }
//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(); //} } }
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 = "click here http://localhost:32207/fa.aspx?id=" + id; dbConnection.Nachricht.Add(new Nachricht("Neue Anfrage", nachricht, senderID, empfID)); dbConnection.SaveChanges(); } }