c# - How to handle duplicate data or avoid clashes? -


we trying build resource booking system , user can make booking location or people in system. multiple users may make multiple bookings same resource same timing.

for example, user a, b , c trying book location-a following timing.

user
=> 17/03/2015 10:00 12:00
=> 17/03/2015 14:00 15:00
=> 18/03/2015 10:00 12:00
=> 18/03/2015 14:00 15:00

user b
=> 17/03/2015 11:00 12:00
=> 18/03/2015 10:00 12:00

user c
=> 17/03/2015 11:30 13:30

the system needs handle resource clashes avoid double booking same timing or overlap timing. 1 of user can take resource , rest booking must failed. question proper way handle it? should use transaction or table lock before insert data table? using visual studio 2008 , sql server 2008. thank advise , appreciate it.

there @ least 2 business processes involved here.

  • process one:

show available seats.

  • process two:

book location.

since these processes don't follow 1 immoderately, , since 2 people may select same location-a concurrency issue arises.

if database design assigns correct uniqueness constraint combination of:

-locationid

-timestamp (e.g 10 12 ,15 17)

are unique, database prevent duplicates.

the following scenario possible taken care of above suggested implementation:

assuming grid view of available given theater , given event can displayed:

  1. user1 displays available resource (and gets=> 17/03/2015 10:00 12:00 location a)
  2. user2 displays available seats (and gets => 17/03/2015 10:00 12:00 location a)
  3. user1 talks bit on phone
  4. user2 goes , books (17/03/2015 10:00 location a)
  5. user1 tries book (17/03/2015 10:00 location a) (because shows available on screen)
  6. the unique index prevents step 5 commuting data.

so need may nothing more correct database design , proper choice on constraints.

other more complex approaches possible if want, using transaction queues. in case, requests written first queue fires process every n seconds hardly necessary or practical in case.

the interesting part should list grid user 1 show?


Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

[C++][SFML 2.2] Strange Performance Issues - Moving Mouse Lowers CPU Usage -

ios - Possible to get UIButton sizeThatFits to work? -