samedi 26 mars 2016

Pattern for overriding db records

I'm looking for a pattern or code example where a user can enter their own records, that override the default records. For example a Holiday table.

Defaults records may be:

HolidayName  Holiday Date  CompanyId
-----------  ------------  ---------
New Year     01-Jan-2016   NULL
Day After    02-Jan-2016   NULL 

And after the user adds their own holidays (for CompanyId "1234"):

HolidayName  Holiday Date  CompanyId
-----------  ------------  ---------
New Year     01-Jan-2016   NULL
Day After    02-Jan-2016   NULL
Another Name 01-Jan-2016   1234
My Holiday   03-Jan-2016   1234 
Joes Holiday 04-Jan-2016   5678 

How can I retrive a list of holidays that are a compinbation of: 1. the default Holidays (where CompanyId = NULL), or 2. the overridden holidays (with the same date),
3. And includes additional holidays entered by the user (by CompanyID). Like this for companyId=1234:

HolidayName  Holiday Date  CompanyId
-----------  ------------  ---------
Another Name 01-Jan-2016   1234
Day After    02-Jan-2016   NULL
My Holiday   03-Jan-2016   1234     

Not sure if this could done in either a SQL view, Query or C# code.

Aucun commentaire:

Enregistrer un commentaire