本文整理汇总了C#中ProductRepository.SaveOrUpdate方法的典型用法代码示例。如果您正苦于以下问题:C# ProductRepository.SaveOrUpdate方法的具体用法?C# ProductRepository.SaveOrUpdate怎么用?C# ProductRepository.SaveOrUpdate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ProductRepository
的用法示例。
在下文中一共展示了ProductRepository.SaveOrUpdate方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PrepareProducts
private void PrepareProducts()
{
var productRepository = new ProductRepository();
_finishGood1 = new Product { ProductType = ProductType.FinishGood, Name = "F1", DrawingNumber = "6606"};
_finishGood2 = new Product { ProductType = ProductType.FinishGood, Name = "F2", DrawingNumber = "9393"};
_rawMaterial1 = new Product { ProductType = ProductType.RawMaterial,Name = "R1"};
_rawMaterial2 = new Product { ProductType = ProductType.RawMaterial,Name = "R2"};
productRepository.SaveOrUpdate(_finishGood1);
productRepository.SaveOrUpdate(_finishGood2);
productRepository.SaveOrUpdate(_rawMaterial1);
productRepository.SaveOrUpdate(_rawMaterial2);
FlushAndClearSession();
}
示例2: 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);
}