c# - Rollback after saving changes -


i have controller , repository. using ef 6

controller file

int userid = _myrepository.addcustomer(model) 

i userid

then using third party plugin make payment (ex:)

var success = makepaymentthroughpaymentprocessor(userid); 

now if payment not go through or error happens rollback changes no customer added not added database.

i have tried using wrapping repository method

(var transaction = objmcoentities.database.begintransaction()) { //code... context.savechanges(); return userid; 

i on https://msdn.microsoft.com/en-us/data/dn456843.aspx

but i'm not sure how reference transaction after addcustomer repository methods has been called

i take payment first , add customer db after if error happens while adding customer db customer not created payment made , have refund customer

if you're using entity framework 6, have @ this page. you'll have choose between tranaction.commit() , transaction.rollback();

but don't think necessary in scenario. if have right sequence in code (first payment via third party tool , save db), don't need transaction, don't know specifics of third party tool.


Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo