本文整理汇总了C#中ProductRepository.Get方法的典型用法代码示例。如果您正苦于以下问题:C# ProductRepository.Get方法的具体用法?C# ProductRepository.Get怎么用?C# ProductRepository.Get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ProductRepository
的用法示例。
在下文中一共展示了ProductRepository.Get方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Index
// GET: Product
public ActionResult Index(string sort = "Name", bool sortReverse = false, int pageNumber = 1, string searchFor = "")
{
ViewBag.CurrentSort = sortReverse;
using (var productRep = new ProductRepository())
{
ViewBag.OnePageOfProducts = ((List<Product>)productRep.Get(sort, ViewBag.CurrentSort, searchFor)).ToPagedList(pageNumber, 10);
}
var allProducts = new List<ProductViewModel>();
foreach (var item in ViewBag.OnePageOfProducts)
{
allProducts.Add(new ProductViewModel()
{
Id = item.Id,
Name = item.Name,
Description = item.Description,
Preco = item.Preco,
PhotoOutput = item.Photo == null ? string.Empty :
String.Format("data:image/gif;base64,{0}", Convert.ToBase64String(item.Photo))
});
}
ViewBag.AllProducts = allProducts;
return View();
}
示例2: ProductRepositoryAddNewItemSaveItem
public void ProductRepositoryAddNewItemSaveItem()
{
//Arrange
var unitOfWork = new MainBCUnitOfWork();
IProductRepository productRepository = new ProductRepository(unitOfWork);
var book = new Book()
{
Id = IdentityGenerator.NewSequentialGuid(),
ISBN = "ABC",
Publisher = "Krasiss Press",
Title = "The book title",
UnitPrice = 40,
Description = "Any book description",
AmountInStock = 1
};
//Act
productRepository.Add(book);
productRepository.UnitOfWork.Commit();
//Assert
var result = productRepository.Get(book.Id);
Assert.IsNotNull(result);
Assert.IsTrue(result.Id == book.Id);
}
示例3: Index
public ActionResult Index(int pageNumber = 1)
{
using (var productRep = new ProductRepository())
{
ViewBag.OnePageOfProducts = productRep.Get().ToPagedList(pageNumber, 8);
}
var allProducts = new List<ProductViewModel>();
foreach (var item in ViewBag.OnePageOfProducts)
{
allProducts.Add(new ProductViewModel()
{
Id = item.Id,
Name = item.Name,
Description = item.Description,
Preco = item.Preco,
PhotoOutput = item.Photo == null ? string.Empty :
String.Format("data:image/gif;base64,{0}", Convert.ToBase64String(item.Photo))
});
}
var countProducts = allProducts.Count();
ViewBag.FirstRowOfProductList = countProducts.Equals(0) ? null : allProducts.Take(4);
if (countProducts > 4)
ViewBag.SecondRowOfProductList = countProducts.Equals(0) ? null : allProducts.GetRange(4, countProducts - 4);
return View();
}
示例4: ProductRepositoryGetMethodReturnNullWhenIdIsEmpty
public void ProductRepositoryGetMethodReturnNullWhenIdIsEmpty()
{
//Arrange
var unitOfWork = new MainBcUnitOfWork();
var productRepository = new ProductRepository(unitOfWork);
Product product = null;
//Act
product = productRepository.Get(Guid.Empty);
//Assert
Assert.IsNull(product);
}
示例5: ProductRepositoryGetMethodReturnMaterializedEntityById
public void ProductRepositoryGetMethodReturnMaterializedEntityById()
{
//Arrange
var unitOfWork = new MainBcUnitOfWork();
IProductRepository productRepository = new ProductRepository(unitOfWork);
var productId = new Guid("44668EBF-7B54-4431-8D61-C1298DB50857");
Product product = null;
//Act
product = productRepository.Get(productId);
//Assert
Assert.IsNotNull(product);
Assert.IsTrue(product.Id == productId);
}
示例6: can_fetch_product
public void can_fetch_product()
{
Product product = null;
using(var session = _sessionFactory.Open())
{
var repo = new ProductRepository(session);
product = repo.Get(1);
}
Assert.NotNull(product);
Assert.NotNull(product.Description);
Assert.NotNull(product.Name);
Assert.NotNull(product.Price);
Assert.NotNull(product.Brand);
Assert.NotNull(product.Categories);
Assert.NotNull(product.Colors);
Assert.NotNull(product.Sizes);
}