本文整理汇总了C#中IProductRepository.SaveCategory方法的典型用法代码示例。如果您正苦于以下问题:C# IProductRepository.SaveCategory方法的具体用法?C# IProductRepository.SaveCategory怎么用?C# IProductRepository.SaveCategory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IProductRepository
的用法示例。
在下文中一共展示了IProductRepository.SaveCategory方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReaderFile
public void ReaderFile(IProductRepository repository)
{
//Сохраняем для остальных методов
_repo = repository;
/********ОЧИЩАЕМ КАТЕГОРИИ и ПОДКАТЕГОРИИ********/
int countcategory = repository.Categories.Count();
for(int i=0; i < countcategory; i++)
{
var id = repository.Categories.First().CategoryId;
DeleteIdSubcategory(id);
}
/********ОЧИЩАЕМ КАТЕГОРИИ и ПОДКАТЕГОРИИ********/
/***********ИНИЦИАЛИЗИРУЕМ из файла КАТЕГОРИИ*************/
var cn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source =" + _pathfile +
";Persist Security Info=False;");
//Строка запросв
string query = "SELECT * FROM Category";
var cmd = new OleDbCommand(query, cn);
cn.Open();
OleDbDataReader dr = cmd.ExecuteReader();
//Считываем первый столбец Категория
while (dr.Read())
{
//Инициализируем список Subcategory
var category = new Category
{Subcatigories = new List<Subcategory>(),
CategoryName = dr.GetString(1),
Sequence = dr.GetInt32(3)
};
repository.SaveCategory(category);
}
/***********ИНИЦИАЛИЗИРУЕМ из файла КАТЕГОРИИ*************/
/***********ИНИЦИАЛИЗИРУЕМ из файла ПОДКАТЕГОРИИ*************/
query = "SELECT * FROM Subcategory";
cmd = new OleDbCommand(query, cn);
dr = cmd.ExecuteReader();
while (dr.Read())
{
var subcategory = new Subcategory { SubcategoryName = dr.GetString(2)};
string categoryName = dr.GetString(1);
var category = repository.Categories
.Where(o => o.CategoryName == categoryName)
.Select(o => o)
.First();
category.Subcatigories.Add(subcategory);
repository.SaveCategory(category);
}
/***********ИНИЦИАЛИЗИРУЕМ из файла ПОДКАТЕГОРИИ*************/
dr.Close();
cn.Close();
}
示例2: SampleMethod
private static void SampleMethod(IProductRepository productRepo)
{
SessionProvider.RebuildSchema();
//Add a Unit of Measure
var uomCrate = new UnitOfMeasure { UomDescription = "Crate" };
productRepo.SaveUOM(uomCrate);
//Add some categories
var catA = new Category { CategoryName = "Metals" };
var catB = new Category { CategoryName = "Plastics" };
var catC = new Category { CategoryName = "Recycled Goods" };
var catD = new Category { CategoryName = "New Materials" };
productRepo.SaveCategory(catA);
productRepo.SaveCategory(catB);
productRepo.SaveCategory(catC);
productRepo.SaveCategory(catD);
//Add some products
var prod01 = new Product { ProductName = "Copper Wire", UOM = uomCrate };
var prod02 = new Product { ProductName = "Refurbished Sprockets", UOM = uomCrate };
var prod03 = new Product { ProductName = "Plastic Housings", UOM = uomCrate };
var prod04 = new Product { ProductName = "Used Bubble Wrap", UOM = uomCrate };
//Assign some Categories
prod01.Categories.Add(catA);
prod01.Categories.Add(catD);
prod02.Categories.Add(catA);
prod02.Categories.Add(catC);
prod03.Categories.Add(catB);
prod03.Categories.Add(catD);
prod04.Categories.Add(catB);
prod04.Categories.Add(catC);
//Persist our objects
productRepo.Save(prod01);
productRepo.Save(prod02);
productRepo.Save(prod03);
productRepo.Save(prod04);
var prodTemp = productRepo.GetById(prod01.ProductId);
prodTemp.Categories.RemoveAt(0);
System.Console.WriteLine("Press any key to continue...");
System.Console.Read();
}