public void printRelationshipRequests() { IEnumerable <Datas.RelationshipRequest> relationshipRequests = from ar in Bdd.DbAccess.RelationshipRequests where ar.idCalled == App.user.ID select ar; this.sPRelationshipRequest.Children.Clear(); foreach (Datas.RelationshipRequest request in relationshipRequests) { Datas.User caller = (from u in Bdd.DbAccess.Users where u.ID == request.idCaller select u).FirstOrDefault(); if (caller == null) { return; } Datas.Grade grade = (from g in Bdd.DbAccess.Grades where g.ID == caller.idGrade select g).FirstOrDefault(); if (grade == null) { return; } RequestLine line = new RequestLine(); line.setName(caller.username, caller.ID); line.setGrade(grade.name); this.sPRelationshipRequest.Children.Add(line); } }
public void printFriendsList() { IEnumerable <Datas.Relationship> relationships = from r in Bdd.DbAccess.Relationships where r.userId1 == App.user.ID select r; this.sPRelationship.Children.Clear(); foreach (Datas.Relationship relationship in relationships) { Datas.User friend = (from u in Bdd.DbAccess.Users where u.ID == relationship.userId2 select u).FirstOrDefault(); if (friend == null) { return; } Datas.Grade grade = (from g in Bdd.DbAccess.Grades where g.ID == friend.idGrade select g).FirstOrDefault(); if (grade == null) { return; } FriendLine line = new FriendLine(); line.setName(friend.username, friend.ID); line.setGrade(grade.name); this.sPRelationship.Children.Add(line); } }
public void sendFriendshipRequest() { this.lInvitationSent.Visibility = System.Windows.Visibility.Hidden; this.lUnexistingUser.Visibility = System.Windows.Visibility.Hidden; this.lAlreadyExistingRelationshipRequest.Visibility = System.Windows.Visibility.Hidden; this.lAlreadyExistingRelationship.Visibility = System.Windows.Visibility.Hidden; this.lInvitationToMe.Visibility = System.Windows.Visibility.Hidden; string pseudo = this.tBPseudo.Text; this.tBPseudo.Text = ""; Datas.User user = (from u in Bdd.DbAccess.Users where u.username.ToUpper() == pseudo.ToUpper() select u).FirstOrDefault(); if (user == null) { this.lUnexistingUser.Visibility = System.Windows.Visibility.Visible; return; } if (user.ID == App.user.ID) { this.lInvitationToMe.Visibility = System.Windows.Visibility.Visible; return; } Datas.Relationship relationship = (from r in Bdd.DbAccess.Relationships where (r.userId1 == App.user.ID && r.userId2 == user.ID) || (r.userId1 == user.ID && r.userId2 == App.user.ID) select r).FirstOrDefault(); if (relationship != null) { this.lAlreadyExistingRelationship.Visibility = System.Windows.Visibility.Visible; return; } Datas.RelationshipRequest relationshipRequest = (from rr in Bdd.DbAccess.RelationshipRequests where (rr.idCaller == App.user.ID && rr.idCalled == user.ID) || (rr.idCalled == App.user.ID && rr.idCaller == user.ID) select rr).FirstOrDefault(); if (relationshipRequest != null) { this.lAlreadyExistingRelationshipRequest.Visibility = System.Windows.Visibility.Visible; return; } Datas.RelationshipRequest addRequest = new Datas.RelationshipRequest() { idCaller = App.user.ID, idCalled = user.ID }; Bdd.DbAccess.AddToRelationshipRequests(addRequest); Bdd.DbAccess.SaveChanges(); this.lInvitationSent.Visibility = System.Windows.Visibility.Visible; }
/// <summary> /// Inscription /// </summary> /// <returns></returns> private bool RegisterUser() { string uName = this.textBoxInscrPseudo.Text; DateTime uDate = this.dateBirth.DisplayDate; string uPass = this.passwordBoxInscr.Password; bool check = true; if (uName.Equals(String.Empty)) { this.lUsername.Content = "Veuillez saisir\nun nom d'utilisateur"; check = false; } else { Datas.User alreadyExistingUser = (from i in Bdd.DbAccess.Users where uName.ToUpper() == i.username.ToUpper() select i).FirstOrDefault(); if (alreadyExistingUser != null) { this.lUsername.Content = "Veuillez saisir un\nautre nom d'utilisateur"; check = false; } } if (uPass.Equals(String.Empty)) { this.lPass.Content = "Veuillez saisir\nun mot de passe"; check = false; } if (!uPass.Equals(this.tPassBis.Password)) { this.lNotCorrespond.Content = "Les mots de passe\n ne correspondent pas"; check = false; } if (!check) { return(false); } string passhash = Bdd.SHA1(uPass); try { Datas.Grade grade = (Datas.Grade) this.comboBoxInscrForm.SelectedItem; Datas.User u = new Datas.User() { username = this.textBoxInscrPseudo.Text, password = passhash, mail = this.textBoxInscrMail.Text, firstName = this.textBoxInscrPrenom.Text, name = this.textBoxInscrNom.Text, birthDate = uDate, idRank = App.RankStudent, idGrade = grade.ID }; Bdd.DbAccess.AddToUsers(u); Bdd.DbAccess.SaveChanges(); App.user = u; return(true); } catch (Exception) { this.lError.Content = "Erreur lors de l'ajout de l'inscription dans la BDD,\n le nom d'utilisateur est peut-être déjà existant.\nVeuillez réesayer ou contacter un administrateur."; return(false); } }
/// <summary> /// Connexion /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Login(object sender, RoutedEventArgs e) { string shaPass = Bdd.SHA1(this.passwordBoxConn.Password); Datas.User user = (from u in Bdd.DbAccess.Users where u.username == this.textBoxConn.Text && u.password == shaPass select u).FirstOrDefault(); if (user != null) { App.user = user; App.mainWindow.ConnexionControlClicked(true); } else { this.lCo.Content = "Utilisateur ou mot de passe incorrect !"; } }
private void DisplayFriends() { foreach (Datas.Relationship item in this.listeFriends) { Datas.User user = (from i in Bdd.DbAccess.Users where i.ID == item.userId2 select i).FirstOrDefault(); if (user != null) { string grade = (from i in Bdd.DbAccess.Grades where user.idGrade == i.ID select i.name).FirstOrDefault(); Button bt = new Button() { Content = string.Format("{0} ({1})", user.username, grade), Tag = item.userId2, FontSize = 20, Padding = new Thickness(20), Margin = new Thickness(10) }; bt.Click += new RoutedEventHandler(Bt_Click); this.stackPanelFriends.Children.Add(bt); } } }
/// <summary> /// Cherche l'utilisateur entré et modifie le rang /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void bModifRank_Click(object sender, RoutedEventArgs e) { this.lUnexistingUser.Visibility = System.Windows.Visibility.Hidden; this.lModRankSuccess.Visibility = System.Windows.Visibility.Hidden; string pseudo = this.tBPseudo.Text; Datas.User user = (from u in Bdd.DbAccess.Users where u.username.ToUpper() == pseudo.ToUpper() select u).FirstOrDefault(); if (user == null) { this.lUnexistingUser.Visibility = System.Windows.Visibility.Visible; return; } Datas.Rank rank = (Datas.Rank) this.cBRank.SelectedItem; user.idRank = rank.ID; Bdd.DbAccess.SaveChanges(); this.lModRankSuccess.Visibility = System.Windows.Visibility.Visible; }