简体   繁体   中英

Assigning property values to a checkbox mvc c#

Hoping someone can give me a point in the right direction with this.

So i have a working "product" form which employees fill in and the results show on a table. I've added an "approved" check box to this form, again the result of this being checked or not is displayed in the table.

However, as any employee can edit this I would like a record of who checks and unchecks the box in my database. So I've added a checkedBy and checkboxDate to the "product" database table and model.

I'm just wondering is this the right way to go about this or if I should have my own table, model, properties etc for the checkbox?

My suggestion would be to have a separate table with 4 columns - UpdatedBy (saves who made an update), UpdateDate(ie when was update made may be system date), Component(which part or page name was updated) and Section(which value or control was updated). This will help you to use this table for any such future change across the product.

It is totally normal solution. If checkbox is in a relationship with "product" it is normal to add some properties to that table that corresponds to that checkbox.

I do not think that is a good solution. So if UserA unchecks the box, you record UserA and Uncheck in the product table for ProductId1 (for example). Then when UserB checks this, you overwrite those values in ProductId1. Therefore, you are only keeping the last person who checked/unchecked it.

Here is how I have done things like this in the past. In the db, for any table which needs history, I add the following:

  1. UpdatedByUser
  2. EffectiveFrom - This value is the date of whenever the edit is done. In your case the editing is, check and uncheck.
  3. EffectiveTo - If this is null, the current record is the active record. If this has a value, it means the info in this row was current from EffectiveFrom to the EffectiveTo date.

Every time someone makes a change to the record, I set the UpdateByUser and EffectiveTo (to Now) of the current record. Then I insert a new record with existing values and the changed value. This record will have EffectiveTo null (meaning this is the current active record). This way you will know what was changed and you have history as well. At any instance for a given product, only 1 record should have EffectiveTo set to null. The rest should have a value.

Oh and I would not call the column checkedBy, uncheckedBy since this is very ui specific. I would call them ApprovedBy, RejectedBy or something which has meaning to the domain the application is designed for.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM