本文整理汇总了C#中ProductRepository.Retrieve方法的典型用法代码示例。如果您正苦于以下问题:C# ProductRepository.Retrieve方法的具体用法?C# ProductRepository.Retrieve怎么用?C# ProductRepository.Retrieve使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ProductRepository
的用法示例。
在下文中一共展示了ProductRepository.Retrieve方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Get
public IHttpActionResult Get(int id)
{
try
{
Product product;
var productRepository = new ProductRepository();
if (id > 0)
{
var products = productRepository.Retrieve();
product = products.FirstOrDefault(p => p.ProductId == id);
if (product == null)
{
return NotFound();
}
}
else
{
product = productRepository.Create();
}
return Ok(product);
}
catch (Exception ex)
{
return InternalServerError(ex);
}
}
示例2: Get
public IEnumerable<Product> Get(string search)
{
var productRepository = new ProductRepository();
var products = productRepository.Retrieve();
return products.Where(p => p.ProductCode.Contains(search));
}
示例3: Put
// PUT api/products/5
public IEnumerable<Product> Put(int id, [FromBody]Product value)
{
ProductRepository repo = new ProductRepository();
value.ProductId = id;
repo.Update(value);
return repo.Retrieve();
}
示例4: Get
public IHttpActionResult Get()
{
try
{
var productRepository = new ProductRepository();
return Ok(productRepository.Retrieve().AsQueryable());
}
catch (Exception ex)
{
return InternalServerError(ex);
}
}
示例5: Get
// GET: api/Products/5
public IHttpActionResult Get(int id)
{
ProductRepository repo = new ProductRepository();
Product product;
if (id == 0)
{
product = repo.Create();
}
else
{
product = repo.Retrieve().FirstOrDefault(p => p.ProductId == id);
if (product == null)
{
return NotFound();
}
}
return Ok(product);
}
示例6: Get
// GET: api/Products
public IEnumerable<Product> Get()
{
var productsRepository = new ProductRepository();
return productsRepository.Retrieve();
}
示例7: Post
// POST api/products
public IEnumerable<Product> Post([FromBody]Product value)
{
ProductRepository repo = new ProductRepository();
repo.Save(value);
return repo.Retrieve();
}