2012-10-29 181 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

我不确定这是否是其他人的做法,但我实际上有两种模式。我有我的商业模式,其中包含这些功能和验证。账户余额等东西不能小于零或类似的东西。一旦完成所有这些工作,模型将被转换成数据库模型,并在必要时负责数据库级验证和数据库操作。