MVC架构 - 模式 [英] MVC architecture - patterns

查看:139
本文介绍了MVC架构 - 模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一些帮助的MVC架构。我用下面的架构的命名对象的用户。

I need some help with MVC architecture. I use the following architecture for an object named User.

UserRepository - > IUserRepository - > UserService - > IUserService - > UserController的

UserRepository -> IUserRepository -> UserService -> IUserService -> UserController

用户对象来自我的数据库,我使用的EntityFramework。我有一个返回用户Return_All_Users列表()的功能。一个得到返回的领域之一是的UserType。这出来的一个数字,但是当我表现出我的Index.aspx页的列表中,我想它显示为一个字符串。在用户类型的数量需要寻找到一个字典,发现像管理员的个数伴随而来的字符串,我想这个字符串在我的索引页显示。

The User object comes from my database and I'm using EntityFramework. I have a function that returns a list of users Return_All_Users(). One of the fields that gets returned is "UserType". This comes out as a number, but when I show the list in my Index.aspx page, I would like it to show as a string. The number for "UserType" needs to look into a Dictionary to find the string that goes along with the number like "Administrator" and I would like this string to show in my Index page.

我将如何去这样做呢?我目前使用此功能:

How would I go about doing this? I'm currently using this function:

  public IEnumerable<User> Return_All_Users()
{
  //my code here
}

我有另一篇文章的一个类似的问题,并建议我应该的IEnumerable返回一个字符串,而不是用户对象。我试过了,但后来我与动态模型工作,我不想这样做。我也不知道如何与动态模型的工作,所以我想也许有这样做的更好的方法。

I had another post for a similar question, and it was suggested that my IEnumerable should return a string, not the User object. I tried that, but then I'm working with a Dynamic model and I didn't want to do that. Nor do I know how to work with a Dynamic model, so I thought maybe there is a better way of doing this.

如果发生这种情况在我的UserService?也许我需要创建一个名为NEWUSER新类,定义用户类型为字符串,然后实例化一个新的NEWUSER,并从用户传递的价值。在用户类型传递之前,我会看在字典,并获得关键的正确值。

Should this happen in my UserService? Maybe I need to create a new class called NewUser, and define the UserType as a string, then instantiate a new NewUser and pass the value from User. Before the UserType is passed, I would look in the dictionary and get the correct value for the key.

我应该这样做,或是否有更好的办法?

Should I do that, or is there a better way?

我张贴了这个问题之后,我只是想用存储过程这样做的。也许使用存储过程在我的数据库返回数据,而不是直接从我的数据库表中查找我的数据。

After I posted this question, I just thought of doing this with a stored procedure. Maybe use a stored procedure in my database to return the data, as opposed to looking up my data straight from my database table.

推荐答案

我想创建一个视图模型UserView被格式化,以重新presentation如何您认为会充分利用这些数据。你可以从用户执行映射到存储库或控制器内UserView取决于你preFER做这种映射。

I would create a View Model UserView that was formatted to the representation of how your view would best use that data. You could perform the mapping from User to UserView within your Repository or Controller depending on where you prefer doing this kind of mapping.

这篇关于MVC架构 - 模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆