I'm creating a website that user can become resellers and sell things and that money get added to there credit.
I'm using ASP.net (C#), Linq-to-SQL and SQL Server 2008 R2 and I was wondering if a certain problem could ever happen:
My userinfo
table is something like this:
ID
username
password
credit
isactive
when a user sell something, the Credit
column must be added with 99% of that product price, and I do this in my code like this:
PayDBDataContext db = new PayDBDataContext(ConnectionStrings.ConnectionString);
UserInfo ui = db.UserInfos.SingleOrDefault(x => x.ID == userID);
if(ui.isactive==false)
return;
int p= (int)(newSell.Price*0.99);
//---and maybe some other more time consuming calculations
ui.credit+=p;
db.SubmitChanges();
db.Connection.Close();
My questions:
Is it possible that after I have extracted UI record from database and before db.submitchanges()
value of credit
column in database changes and my ui.credit
won't be reliable? Like if that user just sells something else in that short time?