public bool FillProducts(repositories.Product productRepository, repositories.Category categoryRepository) { SQLiteCommand command = new SQLiteCommand("SELECT * FROM product", db.connection); SQLiteDataReader reader = command.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { int id = reader.GetInt32(0); string sku = reader.GetString(1); string name = reader.GetString(2); double price = Convert.ToDouble(reader.GetDecimal(3)); dynamic category = null; string image; int amount; if (!reader.IsDBNull(5)) { image = reader.GetString(5); } else { image = null; } if (!reader.IsDBNull(6)) { amount = reader.GetInt32(6); } else { amount = 0; } if (!reader.IsDBNull(4)) { category = categoryRepository.FindOne(reader.GetInt32(4)); } else { category = null; } entities.Product product = new entities.Product(id, sku, name, price, category, image, amount); productRepository.Add(product); } } reader.Close(); return(true); }
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 Tuple <int, int, int> LoadProducts(repositories.Product products, repositories.Category categories) { List <string[]> lines = ParseCsv(GetCsvString("products")); int added = 0, changeprice = 0, changeamount = 0; foreach (string[] line in lines) { int id = Convert.ToInt32(line[0]); string sku = line[1]; string name = line[2]; double price; if (line[3] == "") { price = 0; } else { price = Convert.ToDouble(line[3]); } int category_id; if (line[4] != "") { category_id = Convert.ToInt32(line[4]); } else { category_id = 0; } string image = line[5]; int amount; if (line[6] != "") { amount = Convert.ToInt32(line[6]); } else { amount = 0; } entities.Product product = products.FindOne(id); if (product == null) { dynamic category; if (category_id != 0) { category = categories.FindOne(category_id); } else { category = null; } entities.Product addProduct = new entities.Product(id, sku, name, price, category, image, amount); products.SaveWithSql(addProduct); added++; } else { if (product.GetPrice() != price) { changeprice++; } if (product.GetAmount() != amount) { changeamount++; } product.SetName(name); product.SetSku(sku); product.SetCategoryId(category_id); product.SetPrice(price); product.SetImage(image); product.SetAmount(amount); products.SaveWithSql(product); } } return(new Tuple <int, int, int>(added, changeprice, changeamount)); }