简体   繁体   中英

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.

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.

There are two issues that now exists.

  1. 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.

  2. 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:

  1. Pessimistic concurrency (locking).

    You need to implement a locking system where you issue locks on readonly or update/delete

  2. Optimistic concurrency

    Add a LastUpdated timestamp column to your table and use it in WHERE (along with the ID) on update/delete. If 0 rows are affected, then you are trying to update/delete out of date data.

Read this about how to handle this in 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. You can broadcast in realtime that the values where changed and even load the new values.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM