c# - 使用 ASP.NET MVC 和实体框架保持库存水平
问题描述
我正在尝试构建一个跟踪商店库存水平的应用程序。我遇到的问题是您可以同时从手头的数量中扣除多个“职员”。我知道并发是必需的,但我不确定如何处理它。为简单起见,我有以下代码:
public class Inventory{
public int InventoryId {get;set;}
public string InventoryName {get;set;}
public double InventoryValue {get;set;}
public virtual ICollection<Products> ProductsInInventory {get;set;}
}
public class Product{
public int ProductId{get;set;}
public string Name {get;set;}
public double MinLevel {get;set;}
public double ReorderAmount {get;set;}
public double CurrentAmount {get;set;}
[ForeignKey("InInventory")]
public int InventoryId {get;set;}
public virtual Inventory InInventory {get;set;}
[ConcurrencyCheck]
[Timestamp]
public byte[] RowVersion { get; set; }
}
public class ProductOrder{
public int ProductOrderId {get;set;}
public virtual Product OrderProduct {get;set;}
[ForeignKey("OrderProduct")]
public int ProductId {get;set;}
public virtual Order InOrder {get;set;}
[ForeignKey("InOrder")]
public int OrderId {get;set;}
public double AmountProduct {get;set;}
}
public class Order{
public int OrderId {get;set;}
public DateTime DateOfOrder {get;set;}
public virtual List<ProductOrder> ProductsOnOrder {get;set;}
public double OrderAmount {get;set;}
}
对此的任何帮助将不胜感激。我知道我必须将此部分添加到代码中:
catch (DbUpdateConcurrencyException ex)
{
var entry = ex.Entries.Single();
var productValues = (Product)entry.Entity;
var databaseEntry = entry.GetDatabaseValues();
if (databaseEntry == null)
{
ModelState.AddModelError(string.Empty,"Unable to save changes. The product was deleted by another user.");
}
else{
**This is where I assume I would deduct the product amount. I am unsure of how to deduct from the new amount as it can be a high volume system.**
}
}
catch (RetryLimitExceededException /* dex */)
{
//Log the error (uncomment dex variable name and add a line here to write a log.)
ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists, see your system administrator.");
}
谢谢你们每一个人的帮助!!
解决方案
推荐阅读
- strapi - 无权在strapi中查看此字段
- pine-script - PineScript - Strategy.entry 订单金额
- css - 如何在其他 css 文件中使用 react bootstrap 主题
- javascript - Graphql 事件日期已过,如何自动更新完成?
- reactjs - 每次我运行 npm start 我都会收到以下错误
- java - 获取或使用函数类中 sharedpreferences 的值
- r - 交叉加入自身 RStudio
- python - 使用 Django SocialAuth 应用程序时出现模板渲染错误
- javascript - 反应:没有在 {{URL}} 解析样式表,因为在严格模式下不允许非 CSS MIME 类型 & SyntaxError: Unexpected Token '<'
- c++ - 在模板中
It 是一个迭代器的函数,我可以让 It::value_type 对 vector::iterators 和 array::iterators 都有效吗?