I have created a project using MVC Unit Of Work Repository Pattern.
I have implemented CRUD operation using repository pattern.
I have total 4 tables like 1) Master Table, 2) to 4) Detail Table.
Now I have a bellow situation I filled all text box on above form & click on save button. By using repository I am going to Insert data one by one i.e will store data into Master Details then Details 1 to Details 4.
But after inserting data into first 2 tables, because of some wrong information tables 3 & 4 are not inserted. So in this situation I would like to revert data from Master details and Details Table 1.
How can I use Begin Transaction, commit, rollback using repository pattern.
Bellow is my code
-
- MasterDetails objMaster= new MasterDetails();
- objMaster.RFQ = UserTextValue;
- objMaster.CompanyCode = UserTextValue;
-
- UnitoffWork.MasterDetailsRepository.Insert(objMaster);
- UnitoffWork.MasterDetailsRepository.Save();
-
-
- Details1 objD1= new Details1();
- objD1.RFQDate = UserTextValue;
- objD1.Item = UserTextValue;
- //other fields
- UnitoffWork.DetailsOneRepository.Insert(objD1);
- UnitoffWork.DetailsOneRepository.Save();
-
-
- Details2 objD2= new Details2();
- objD2.TargVal = UserTextValue;
- UnitoffWork.DetailsTwoRepository.Insert(objD2);
- UnitoffWork.DetailsTwoRepository.Save();
-
-
- Details3 objD3= new Details3();
- objD3.YourReference = UserTextValue;
- //other fields
- UnitoffWork.DetailsThreeRepository.Insert(objD3);
- UnitoffWork.DetailsThreeRepository.Save();
Thanks