[英]In ASP.NET MVC, how can I avoid or alert people from editing the same form or trying to edit stale data?
I have an ASP.NET MVC site, and I have a web page where you can see aa list of orders.我有一个 ASP.NET MVC 站点,还有一个 web 页面,您可以在其中看到订单列表。
You can double-click on a row and that will open up a detail page (an entitled user will see a large form with lot of text boxes, text areas, radio buttons, etc.).您可以双击一行,这将打开一个详细信息页面(授权用户将看到一个带有大量文本框、文本区域、单选按钮等的大表单)。
Originally there was only one entitled person to an order, so no issues, but now the users are forming teams and in some cases there are several people (10+) that are entitled to edit the same order, so they may have the detail web page up at the same time.最初只有一个有权编辑订单的人,所以没有问题,但现在用户正在组建团队,在某些情况下有几个人(10+)有权编辑同一个订单,所以他们可能有详细信息 web同时向上翻页。
There are two issues that now exists.现在存在两个问题。
People are now complaining that they are making changes that are immediately getting overridden, because other people are editing the same orders at the same time and it's creating a lot of confusion.人们现在抱怨他们所做的更改立即被覆盖,因为其他人在同一时间编辑相同的订单,这造成了很多混乱。
If people are leaving the detail page up all day, they might have a very old version of the view (as multiple other people may have saved changes throughout the day).如果人们整天都离开详细信息页面,他们可能会有一个非常旧的视图版本(因为其他人可能一整天都保存了更改)。 Nothing notified them that their version of the page is out of date and then should refresh the page before editing.
没有任何通知他们他们的页面版本已过时,然后应该在编辑之前刷新页面。
I am looking for suggestions on the best way to deal with the two issues above.我正在寻找有关处理上述两个问题的最佳方法的建议。
Also, if there are certain libraries or patterns that can be leveraged (versus building something from scratch).此外,如果有某些库或模式可以利用(相对于从头开始构建)。
Regarding concurrency, you have two options:关于并发,您有两种选择:
Pessimistic concurrency (locking).悲观并发(锁定)。
You need to implement a locking system where you issue locks on readonly or update/delete您需要实施一个锁定系统,在该系统中您对只读或更新/删除发出锁定
Optimistic concurrency乐观并发
Add a LastUpdated
timestamp column to your table and use it in WHERE
(along with the ID) on update/delete.将
LastUpdated
时间戳列添加到您的表中,并在更新/删除时在WHERE
(连同 ID)中使用它。 If 0 rows are affected, then you are trying to update/delete out of date data.如果 0 行受到影响,那么您正在尝试更新/删除过时的数据。
Read this about how to handle this in ASP.NET MVC with Entity Framework .在 ASP.NET MVC with Entity Framework中阅读有关如何处理此问题的信息。
You can also implement a system to notify that users on the same page.您还可以实施一个系统来通知同一页面上的用户。 One way is to use SignalR and creating a group per page.
一种方法是使用SignalR并为每个页面创建一个组。 You can broadcast in realtime that the values where changed and even load the new values.
您可以实时广播更改的值,甚至加载新值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.