public bool FillClients(repositories.Client clientRepository) { SQLiteCommand command = new SQLiteCommand("SELECT * FROM client", db.connection); SQLiteDataReader reader = command.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { string phone; if (!reader.IsDBNull(2)) { phone = reader.GetString(2); } else { phone = ""; } entities.Client client = new entities.Client(reader.GetInt32(0), reader.GetString(1), phone); clientRepository.Add(client); } } reader.Close(); return(true); }
public Tuple <int> LoadClients(repositories.Client clients) { List <string[]> lines = ParseCsv(GetCsvString("clients")); int added = 0; foreach (string[] line in lines) { int id = Convert.ToInt32(line[0]); string name = line[1]; string phone = line[2]; entities.Client client = clients.FindOne(id); if (client == null) { entities.Client addClient = new entities.Client(id, name, phone); clients.SaveWithSql(addClient); } else { client.SetId(id); client.SetName(name); client.SetPhone(phone); clients.SaveWithSql(client); added++; } } return(new Tuple <int>(added)); }
public int SaveWithSql(entities.Client client) { entities.Client hasClient = FindOne(client.GetId()); SQLiteCommand command; if (hasClient == null) { Add(client); command = new SQLiteCommand("INSERT INTO client(name, phone) VALUES(@name, @phone)", db.connection); } else { command = new SQLiteCommand("UPDATE client SET name = @name, phone = @phone WHERE id = @id ", db.connection); } command.Parameters.AddWithValue("@id", client.GetId()); command.Parameters.AddWithValue("@name", client.GetName()); command.Parameters.AddWithValue("@phone", client.GetPhone()); int num = command.ExecuteNonQuery(); return(num); }
public void Delete(entities.Client client) { clients.Remove(client); }
public void Add(entities.Client client) { clients.Add(client); }