public Product Add(Product product) { context.Product.Add(product); context.SaveChanges(); return(product); }
private void SeedStores(MarketPlaceDbContext dbContext) { var stores = new List <Store> { new Store { store_id = 1, name = "N11", image = "n11.png", ssl = "n11_default_ssl", url = "https://www.n11.com" }, new Store { store_id = 2, name = "Trendyol", image = "trendyol.png", ssl = "trendyol_default_ssl", url = "https://www.trendyol.com" }, new Store { store_id = 3, name = "Hepsiburada", image = "hepsiburada.png", ssl = "hepsiburada_default_ssl", url = "https://www.hepsiburada.com" }, new Store { store_id = 4, name = "Gittigidiyor", image = "gittigidiyor.png", ssl = "gittigidiyor_default_ssl", url = "https://www.gittigidiyor.com" }, new Store { store_id = 5, name = "Cicek Sepeti", image = "ciceksepeti.png", ssl = "ciceksepeti_default_ssl", url = "https://www.ciceksepeti.com" }, }; dbContext.Stores.AddRange(stores); dbContext.SaveChanges(); }
public int AddCategories(IEnumerable <Category> categories) { _dbContext.Categories.AddRange(categories); return(_dbContext.SaveChanges()); }
void SyncLocalOptions() { _connection.Open(); //Load Options(Values) var command = _connection.CreateCommand(); command.LoadScript("SelectOptions_Included_OptionValue"); var dataReader = command.ExecuteReader(); while (dataReader.Read()) { var optionId = (int)dataReader["option_id"]; var option = _dbContext.Options.FirstOrDefault(o => o.option_id == optionId); var isOptionExist = option != null; if (!isOptionExist) { option = new Option(); option.option_id = optionId; option.type = (string)dataReader["option_type"]; option.name = (string)dataReader["option_name"]; option.sort_order = (int)dataReader["option_sort_order"]; } if (dataReader["option_value_id"] != DBNull.Value) { var optionValue = _dbContext.OptionValues.FirstOrDefault(ov => ov.option_value_id == (int)dataReader["option_value_id"]); if (optionValue != null) { optionValue.name = (string)dataReader["option_value_name"]; optionValue.sort_order = (int)dataReader["option_value_sort_order"]; _dbContext.OptionValues.Update(optionValue); } else { optionValue = new OptionValue { option_value_id = (int)dataReader["option_value_id"], option_id = optionId, name = (string)dataReader["option_value_name"], sort_order = (int)dataReader["option_value_sort_order"] }; _dbContext.OptionValues.Add(optionValue); } } if (isOptionExist) { _dbContext.Options.Update(option); } else { _dbContext.Options.Add(option); } _dbContext.SaveChanges(); } //Load ProductOptions(Values) _connection.Close(); _connection.Open(); command = _connection.CreateCommand(); command.LoadScript("SelectProductOptions_Included_ProductOptionValue"); dataReader = command.ExecuteReader(); while (dataReader.Read()) { var productOptionId = (int)dataReader["product_option_id"]; var productOption = _dbContext.ProductOptions.FirstOrDefault(o => o.product_option_id == productOptionId); var isProductOptionExsist = productOption != null; if (!isProductOptionExsist) { productOption = new ProductOption { product_option_id = (int)dataReader["product_option_id"], option_id = (int)dataReader["product_option_option_id"], product_id = (int)dataReader["product_option_product_id"], is_required = (bool)dataReader["product_option_required"], value = (string)dataReader["product_option_value"] }; } else { productOption.is_required = (bool)dataReader["product_option_required"]; productOption.value = (string)dataReader["product_option_value"]; } if (dataReader["product_option_value_id"] != DBNull.Value) { var productOptionValue = _dbContext.ProductOptionValues.FirstOrDefault(po => po.product_option_value_id == (int)dataReader["product_option_value_id"]); if (productOptionValue != null && !productOptionValue.IsChanged) { productOptionValue.option_value_id = (int)dataReader["option_value_id"]; productOptionValue.product_option_id = productOptionId; productOptionValue.quantity = (int)dataReader["product_option_value_quantity"]; productOptionValue.subtract = (bool)dataReader["product_option_value_subtract"]; productOptionValue.point = int.Parse((string)dataReader["product_option_value_points"]); productOptionValue.price = decimal.Parse((string)dataReader["product_option_value_price"], CultureInfo.InvariantCulture); productOptionValue.weight = decimal.Parse((string)dataReader["product_option_value_weight"], CultureInfo.InvariantCulture); _dbContext.ProductOptionValues.Update(productOptionValue); } else { productOptionValue = new ProductOptionValue() { product_option_value_id = (int)dataReader["product_option_value_id"], option_value_id = (int)dataReader["option_value_id"], product_option_id = productOptionId, quantity = (int)dataReader["product_option_value_quantity"], subtract = (bool)dataReader["product_option_value_subtract"], point = int.Parse((string)dataReader["product_option_value_points"]), price = decimal.Parse((string)dataReader["product_option_value_price"], CultureInfo.InvariantCulture), weight = decimal.Parse((string)dataReader["product_option_value_weight"], CultureInfo.InvariantCulture) }; _dbContext.ProductOptionValues.Add(productOptionValue); } } if (isProductOptionExsist) { _dbContext.ProductOptions.Update(productOption); } else { _dbContext.ProductOptions.Add(productOption); } _dbContext.SaveChanges(); } _connection.Close(); command.Dispose(); dataReader.Dispose(); }
public Purchase Add(Purchase purchase) { context.Purchase.Add(purchase); context.SaveChanges(); return(purchase); }