Discard changes made using the latest database

When I click the button, jQuery uses ajax to delete the item, but is it possible to make another function that can β€œundo” the delete that just happened?

My uninstall controller

[HttpPost] public void DeleteProject(int Id) { var Item = from a in db.Project where a.ProjectId.Equals(Id) select a; Project SelectedProject = Item.FirstOrDefault(); ICollection<ProjectProfile> Profiles = SelectedProject.ProjectProfile; ICollection<Member> Members = SelectedProject.Member; db.Member.RemoveRange(Members); db.ProjectProfile.RemoveRange(Profiles); db.Project.Remove(SelectedProject); db.SaveChanges(); RedirectToAction("Index", "Projects"); } 
+5
source share
1 answer

There are several ways to do this. In general, it is too wide to offer a clear solution, but there are some ideas here:

  • Instead of deleting immediately, you can create a task that will run at a specific time that will perform the deletion. Let's say 10 seconds. Within 10 seconds, you will see a cancel button that will cancel the SaveChanges() task.
  • You can cache the element that you delete in the temporary table and restore it
  • You can add the IsDeleted bit to your table and use this to indicate that the record has been deleted, which can be flipped to "un-delete" as desired.
+1
source

All Articles