public bool SetUserInfo(int id, string username, string password) { Connection c = new Connection(); Utilizadores = new UtilizadorDAO(c); // Encontra o utilizador através do seu username Utilizador updated = Utilizadores.FindById(id); if (username != null) { if (Utilizadores.FindByUsername(username) == true) { throw new InvalidOperationException("There already exists a user with the same username!"); } else { updated.Username = username; } } if (password != null) { updated.Password = password; } return(Utilizadores.Update(updated)); }
public bool AddUtilizador(int id, string username, string password, string nome, string email, bool tipo) { Utilizador u = new Utilizador(id, username, password, nome, email, tipo); Connection connection = new Connection(); Utilizadores = new UtilizadorDAO(connection); if (Utilizadores.FindByUsername(username) == true) { throw new System.InvalidOperationException("Already exists a same username... Try other!"); } return(Utilizadores.Insert(u)); }