2012-10-29 179 views
0

我有一些常見的功能,適用於整個我的應用程序更新行爲發生時數據庫的特定部分(審計線索,修改日期等)。我將使用AuditTrail作爲示例。MVC業務邏輯幫手

我應該在哪裏存儲這些功能?

目前,我將它們存儲在的DbContext類

//... my db context class ... 

public bool AddAuditEntry(int ID, string objectName) 
{ 
    // Here I create a new AuditTrail object, assign values then insert into db. 
    // This mode doesn't have a controller. 
} 

// We also have a table that keeps track of modified state for 
// client side caching (nothing I have control over) 
public bool ModifyObject(int ID) 
{ 
    // Here I mark the object id with modified date then save to db 
    // This particular model doesn't have a controller either. 
} 

我認爲他們應該在模型中屬於,但我不太清楚如何實現它。將它們放在控制器中並不是最好的選擇,因爲其中一些僅與可能沒有控制器的特定模型類相關。

與他們在模型中的問題是什麼然後是更新實體的最佳方式?

+0

您是否考慮過使用工廠? – Marko

回答

0

我不確定這是否是其他人的做法,但我實際上有兩種模式。我有我的商業模式,其中包含這些功能和驗證。賬戶餘額等東西不能小於零或類似的東西。一旦完成所有這些工作,模型將被轉換成數據庫模型,並在必要時負責數據庫級驗證和數據庫操作。