I have a class Document and a class Home. I also have made a relation Document_Home.
我有一个班级文件和一个班级家庭。我也建立了一个关系Document_Home。
What I want to do is to select some photos and create them as Documents once the button "Create Home" is pressed.
我想要做的是选择一些照片,并在按下“创建主页”按钮后将其创建为文档。
How should I do this?
我该怎么做?
Document has its own controller with a create method and the same for Home and Document_Home.
Document有自己的控制器和create方法,Home和Document_Home也是如此。
Is there something like a transaction?
有没有像交易一样的东西?
First, create the Home. Second, create the Documents Third, create the relation between Documents and Home.
首先,创建Home。二,创建文档三,创建文档与家庭之间的关系。
1 个解决方案
#1
0
Contrary to my previous comment, you may want to consider using a "repository pattern." You don't need any DB context for this, I just mean create a project in your solution adjacent to your MVC project called "Repositories" and then create a new class that has functionality like this:
与我之前的评论相反,您可能需要考虑使用“存储库模式”。您不需要任何数据库上下文,我只是在您的解决方案中创建一个名为“存储库”的MVC项目旁边的项目,然后创建一个具有以下功能的新类:
public class MyCustomRepo
{
public void MyCreateMethod(List<MyPhotoObject> photos)
{
foreach (var photo in photos)
{
// create home
// create documents
// create relation
}
}
}
This would keep your number of controllers down and would be "SOC" separation of concerns being as this is more data layer than logic layer. I think it would keep your code a lot cleaner.
这将使您的控制器数量减少,并且将关注的“SOC”分离,因为这是比逻辑层更多的数据层。我认为它会让你的代码更清洁。
You'll have to reference the DLL from your repositories project in your MVC project.
您必须从MVC项目中的存储库项目中引用DLL。
#1
0
Contrary to my previous comment, you may want to consider using a "repository pattern." You don't need any DB context for this, I just mean create a project in your solution adjacent to your MVC project called "Repositories" and then create a new class that has functionality like this:
与我之前的评论相反,您可能需要考虑使用“存储库模式”。您不需要任何数据库上下文,我只是在您的解决方案中创建一个名为“存储库”的MVC项目旁边的项目,然后创建一个具有以下功能的新类:
public class MyCustomRepo
{
public void MyCreateMethod(List<MyPhotoObject> photos)
{
foreach (var photo in photos)
{
// create home
// create documents
// create relation
}
}
}
This would keep your number of controllers down and would be "SOC" separation of concerns being as this is more data layer than logic layer. I think it would keep your code a lot cleaner.
这将使您的控制器数量减少,并且将关注的“SOC”分离,因为这是比逻辑层更多的数据层。我认为它会让你的代码更清洁。
You'll have to reference the DLL from your repositories project in your MVC project.
您必须从MVC项目中的存储库项目中引用DLL。