public IEnumerable<Specialist> GetListeners(Client client) { var listeningSpecialists = from keyValuePair in _subscribers from cl in keyValuePair.Value where cl.Username == client.Username select keyValuePair.Key; return listeningSpecialists; }
public bool Unsubscribe(Specialist specialist, Client client) { var listOfClients = GetListBySpecialist(specialist); if (listOfClients == null) return false; var s = listOfClients.Item1; var list = listOfClients.Item2; list.RemoveAll(x => x.Username == client.Username); return _subscribers.TryAdd(s, list); }
public bool Subscribe(Specialist specialist, Client client) { var tuple = GetListBySpecialist(specialist); if (tuple == null) { return _subscribers.TryAdd(specialist, new List<Client>() { client }); } var listOfClients = tuple.Item2; if (listOfClients != null){ // Voeg de extra client toe aan de lijst listOfClients.Add(client); // Voeg de lijst toe aan de dictionary return _subscribers.TryAdd(tuple.Item1, listOfClients); } var tempClient = new List<Client> {client}; return _subscribers.TryAdd(specialist, tempClient); }
public void saveSpecialistWithClient() { Specialist c = new Specialist() { DateOfBirth = DateTime.Now, Gender = "M", Name = "Richard", Surname = "boudewijn", PasswordToBeSaved = "dsffafsad", Username = "******" }; Client client = new Client() { Username = "******" }; int type = (int) c.UserType; bool saveClient = db.saveUser(client); c.Clients.Add(client); bool saveSpecialist = db.saveUser(c); Assert.True(saveSpecialist); }
public void saveClient() { Client c = new Client() { Username = "******", PasswordToBeSaved = "welcome", Surname = "Dinkelburg", Name = "Unknown", DateOfBirth = DateTime.Now, Gender = "m" }; bool clientHasBeenSaved = db.saveUser(c); Assert.True(clientHasBeenSaved); }
public bool ShouldNotify(Client client) { return GetListeners(client).Any(); }
private List<User> readToUser(MySqlDataReader _reader) { List<User> users = new List<User>(); string usersQuery = String.Format("SELECT user_type, {0}.users.id, Username, name, dateOfBirth, surname, gender, password, length, weight FROM {0}.users LEFT JOIN {0}.client_bmi_info on {0}.users.id = {0}.client_bmi_info.users_id ", _database); OpenConnection(); _selectCommand = new MySqlCommand(usersQuery, Connection); while (_reader.Read()) { User u; int type = _reader.GetInt32(0); if (type == 2) { u = new Administrator() { Username = _reader.IsDBNull(2) ? null : _reader.GetString(2), Surname = _reader.IsDBNull(5) ? null : _reader.GetString(5), Name = _reader.IsDBNull(3) ? null : _reader.GetString(3), DateOfBirth = _reader.IsDBNull(4) ? DateTime.MinValue : (DateTime)_reader.GetMySqlDateTime(4), Id = _reader.IsDBNull(1) ? 0 : _reader.GetInt32(1), Gender = _reader.IsDBNull(6) ? null : _reader.GetString(6) }; } else if (type == 1) { u = new Specialist { Username = _reader.IsDBNull(2) ? null : _reader.GetString(2), Surname = _reader.IsDBNull(5) ? null : _reader.GetString(5), Name = _reader.IsDBNull(3) ? null : _reader.GetString(3), DateOfBirth = _reader.IsDBNull(4) ? DateTime.MinValue : (DateTime)_reader.GetMySqlDateTime(4), Id = _reader.IsDBNull(1) ? 0 : _reader.GetInt32(1), Gender = _reader.IsDBNull(6) ? null : _reader.GetString(6) }; } else if (_reader.GetInt32(0) == 0) { u = new Client { Username = _reader.IsDBNull(2) ? null : _reader.GetString(2), Surname = _reader.IsDBNull(5) ? null : _reader.GetString(5), Name = _reader.IsDBNull(3) ? null : _reader.GetString(3), DateOfBirth = _reader.IsDBNull(4) ? DateTime.MinValue : (DateTime)_reader.GetMySqlDateTime(4), Id = _reader.IsDBNull(1) ? 0 : _reader.GetInt32(1), Gender = _reader.IsDBNull(6) ? null : _reader.GetString(6), Lenght = _reader.IsDBNull(8) ? -1 : _reader.GetDecimal(8), Weight = _reader.IsDBNull(9) ? -1 : _reader.GetDecimal(9) }; } else continue; users.Add(u); } _reader.Close(); return users; }
private void _createButton_Click(object sender, EventArgs e) { _connection = new DBConnect(); const string pleaseFillIntext = "Please fill in all fields"; if(string.IsNullOrEmpty(_nameBox.Text) || string.IsNullOrEmpty(_surnameBox.Text) || !_genderMaleRadioButton.Checked && !_genderFemaleRadioButton.Checked ){ MessageBox.Show(pleaseFillIntext); return; } else if (clientRadioButton.Checked && String.IsNullOrEmpty(_lengthBox.Text) || clientRadioButton.Checked && string.IsNullOrEmpty(_weightBox.Text)) { MessageBox.Show(pleaseFillIntext); return; } var gender = _genderMaleRadioButton.Checked ? "m" : "f"; bool succes; //TODO create user with given data, save into db if (clientRadioButton.Checked) { Client client = new Client() { AuthToken = "", DateOfBirth = dateOfBirthPicker.Value, Gender = gender, Weight = Decimal.Parse(_weightBox.Text), Lenght = Decimal.Parse(_lengthBox.Text), Name = _nameBox.Text, Surname = _surnameBox.Text, Username = Usernamebox.Text, PasswordToBeSaved = passwordBox.Text }; succes = _connection.saveUser(client); } else { Specialist specialist = new Specialist() { AuthToken = "", DateOfBirth = dateOfBirthPicker.Value, Name = _nameBox.Text, Gender = gender, PasswordToBeSaved = passwordBox.Text, Username = Usernamebox.Text, Surname = _surnameBox.Text }; succes = _connection.saveUser(specialist); } if (succes) { MessageBox.Show("Success: the user has been added."); this.Close(); } else { MessageBox.Show("Could not add the user."); } }