public Roles GetRoleForUser(User user) { var requeteRoleForUser = from b in db.UserRole where b.IdUser.Id.Equals(user.Id) select b.Roles; return requeteRoleForUser.First(); }
public User DesactiveUser(User user) { user.Active = false; user.FirstName = "null"; user.LastName = "null"; user.Password = "******"; user.Birthday = DateTime.Now; user.City = "null"; user.Email = "null"; user.Gender = 0; user.Avatar = null; return user; }
/// <summary> /// Création de l'utilisateur dans la table USER /// </summary> /// <param name="lastName"></param> /// <param name="firstName"></param> /// <param name="password"></param> /// <param name="email"></param> /// <param name="nickname"></param> /// <returns>Utilisateur crée</returns> public User AjouterUtilisateur(string lastName, string firstName, string password, string email, string nickname) { string pwHash; pwHash = PasswordHash.CreateHash(password); User utilisateur = new User { FirstName = firstName, LastName = lastName, Email = email, Password = pwHash, NickName = nickname }; utilisateur.Birthday = DateTime.Now; utilisateur.Active = true; var userRoleRequete = from b in db.UserRole where b.IdUser.Id.Equals(utilisateur.Id) select b; UserRole userRoleVerify = userRoleRequete.FirstOrDefault(); if (userRoleVerify == null) { UserRole userRole = new UserRole(); userRole.IdUser = utilisateur; userRole.Roles = db.Roles.Find(3); db.UserRole.Add(userRole); } db.Users.Add(utilisateur); db.SaveChanges(); return utilisateur; }
public void UpdatePassword(User user ,string password) { user.Password = password; db.Entry(user).State = EntityState.Modified; db.SaveChanges(); }