本文整理汇总了C#中ProductRepository.Delete方法的典型用法代码示例。如果您正苦于以下问题:C# ProductRepository.Delete方法的具体用法?C# ProductRepository.Delete怎么用?C# ProductRepository.Delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ProductRepository
的用法示例。
在下文中一共展示了ProductRepository.Delete方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Delete
public ActionResult Delete(Guid Id)
{
ProductRepository<Product> dao = new ProductRepository<Product>();
Product produto = dao.ListarPorId(Id);
dao.Delete(produto);
return RedirectToAction("index", "Product");
}
示例2: ShouldDeleteAProduct
public void ShouldDeleteAProduct()
{
var productRepository = new ProductRepository(@"Repository\Products.txt", "Product");
productRepository.Delete(2);
Assert.AreEqual(2,productRepository.GetAll().Count());
}
示例3: Delete
public void Delete(Guid id)
{
ProductRepository p = new ProductRepository(_sqlConnectionString);
p.Delete(id);
}
示例4: Delete
public ActionResult Delete(Product product)
{
try
{
using (var productRep = new ProductRepository())
{
productRep.Delete(product);
}
return RedirectToAction("Index");
}
catch
{
return View();
}
}
示例5: ProcessRequest
public void ProcessRequest(HttpContext context)
{
String output;
try
{
var formCollection = context.Request.Form;
Product prod = new Product();
String prodID = formCollection["id"];
if (prodID.Equals("_empty"))
{
prod.ProductID = 0;
}
else
{
prod.ProductID = Convert.ToInt32(prodID);
}
var operation = formCollection["oper"];
using (ProductRepository repo = new ProductRepository())
{
if (operation.Equals("add") || operation.Equals("edit"))
{
prod.ProductName = formCollection["ProductName"];
prod.SupplierID = Convert.ToInt32(formCollection["SupplierID"]);
prod.UnitPrice = Convert.ToDecimal(formCollection["UnitPrice"]);
prod.UnitsInStock = Convert.ToSByte(formCollection["UnitsInStock"]);
prod.UnitsOnOrder = Convert.ToSByte(formCollection["UnitsOnOrder"]);
if (logger.IsDebugEnabled)
{
logger.Debug("Received request for operation: " + operation + " for Product ID: " + prod.ProductID);
logger.Debug(prod);
}
repo.SaveOrUpdate(prod);
}
else if (operation.Equals("del"))
{
if (logger.IsDebugEnabled)
{
logger.Debug("Received request to delete Product ID: " + prod.ProductID);
logger.Debug(prod);
}
repo.Delete(prod);
}
}
output = "Operation successful.";
}
catch (Exception ex)
{
if (logger.IsDebugEnabled)
{
output = ex.Message;
}
else
{
output = "Oops! We encountered an error while performing the requested operation!";
}
logger.Error(ex);
throw new Exception(output);
}
context.Response.ContentType = "text/plain";
context.Response.Write(output);
}