public bool FillCategories(repositories.Category categoryRepository) { SQLiteCommand command = new SQLiteCommand("SELECT * FROM category", db.connection); SQLiteDataReader reader = command.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { entities.Category category = new entities.Category(reader.GetInt32(0), reader.GetString(1)); categoryRepository.Add(category); } } reader.Close(); return(true); }
public Tuple <int> LoadCategories(repositories.Category categories) { List <string[]> lines = ParseCsv(GetCsvString("categories")); int added = 0; foreach (string[] line in lines) { int id = Convert.ToInt32(line[0]); string name = line[1]; int parent_id; if (line[2] != "") { parent_id = Convert.ToInt32(line[2]); } else { parent_id = 0; } entities.Category category = categories.FindOne(id); if (category == null) { entities.Category addCategory = new entities.Category(id, name); categories.SaveWithSql(addCategory); added++; } else { category.SetId(id); category.SetName(name); category.SetParentId(parent_id); categories.SaveWithSql(category); } } return(new Tuple <int>(added)); }
public int SaveWithSql(entities.Category category) { entities.Category hasCategory = FindOne(category.GetId()); SQLiteCommand command; if (hasCategory == null) { Add(category); command = new SQLiteCommand("INSERT INTO category(name, parent_id) VALUES(@name, @parent_id)", db.connection); } else { command = new SQLiteCommand("UPDATE category SET name = @name, parent_id = @parent_id WHERE id = @id ", db.connection); } command.Parameters.AddWithValue("@id", category.GetId()); command.Parameters.AddWithValue("@name", category.GetName()); command.Parameters.AddWithValue("@parent_id", category.GetParentId()); int num = command.ExecuteNonQuery(); return(num); }
public List <entities.interfaces.CartElement> FindByCategory(entities.Category category) { return(products.FindAll(x => x.GetCategoryId() == category.GetId())); }
public List <entities.Product> FindByCategory(entities.Category category) { return(products.FindAll(x => x.GetCategoryId() == category.GetId())); }
public void Delete(entities.Category category) { categories.Remove(category); }
public void Add(entities.Category category) { categories.Add(category); }