I would like to stop people from constantly syncing/updating items in the DB as this could cause potential problems. I have a time the last sync/update occured which is stored in the DB. What I need to do is disable the user from initiating another update/sync until 15 minutes has passed since the last update/sync.
How would i go about doing this?
Update: for some reason i am getting the error “A new expression requires (), [], or {} after type” on DateTime lastUpdate. Any ideas why this could be?
DataDataContext dc = new DataDataContext();
DateTime lastUpdate = from t in dc.Settings
where t.id == 1
select t.lastSync;
if ((DateTime.Now - lastUpdate).TotalMinutes >= 15)
{
}
else { }
Update: Sorted, i missed off the (); of the datacontext!! facepalm
Final Update: All fixed and working! Many thanks for all your help, for the ones who think this “smells fishy” or “is bad” then here is what i did!!
DateTime lastUpdate = (from t in dc.Settings
where t.id == 1
select t.lastSync).Single();
if ((DateTime.Now - lastUpdate).TotalMinutes >= 15)
{
syncbuttons.Visible = false;
}
else { syncbuttons.Visible = true; }
Now please explain what is so suspect about what i am trying to do? Stopping users from hammering a database? What if i have 30 users attempting to update/sync. Would not be that good would it!
Or, in one line: