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); } }
private void BValidateLevel_Click(object sender, RoutedEventArgs e) { Datas.Grade grade = (Datas.Grade) this.cbLevel.SelectedItem; App.user.idGrade = grade.ID; Bdd.DbAccess.SaveChanges(); this.lLevel.Content = "Changement validé !"; }
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); } }
/// <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); } }