Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/257.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 配置文件和成员身份用户复杂视图模型设计_C#_.net_Asp.net Mvc 3_Viewmodel - Fatal编程技术网

C# 配置文件和成员身份用户复杂视图模型设计

C# 配置文件和成员身份用户复杂视图模型设计,c#,.net,asp.net-mvc-3,viewmodel,C#,.net,Asp.net Mvc 3,Viewmodel,我有我的MVC3Web应用程序的一部分,在这里我需要允许用户管理员管理用户。管理员将能够编辑用户的配置文件信息,以及某些.NET成员身份属性,如用户名、电子邮件、IsLockedOut。我正在努力解决的部分是如何最好地将所有内容包装到自定义模型中 目前我有一个轮廓对象,如下所示: public class Profile { public int ProfileID { get; set; } public Guid UserID { get; set;

我有我的MVC3Web应用程序的一部分,在这里我需要允许用户管理员管理用户。管理员将能够编辑用户的配置文件信息,以及某些.NET成员身份属性,如用户名、电子邮件、IsLockedOut。我正在努力解决的部分是如何最好地将所有内容包装到自定义模型中

目前我有一个轮廓对象,如下所示:

 public class Profile
    {
        public int ProfileID { get; set; }
        public Guid UserID { get; set; }  // link to membership user ID
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public string Phone { get; set; }
    }
我的第一个想法是这样做:

public class ProfileUser
    {
        public ProfileUser(Profile profile)
        {
            Profile = profile;
            User = Membership.GetUser(profile.UserID);
        }

        public Profile Profile { get; set; }
        public MembershipUser User { get; set; }
    }
但是,由于MembershipUser类中的某些字段是只读的,因此我无法直接将带有用户名或islockeOut字段的新值的模型传递回控制器,以更新数据库

然后我考虑将这两个类作为一个类进行包装:

public class ProfileUser : Profile
{
    public ProfileUser(Profile profile)
    {
        this.ProfileID = profile.ProfileID;
        this.UserID = profile.UserID;
        this.FirstName = profile.FirstName;
        this.LastName = profile.LastName;
        this.Phone = profile.Phone;
    }

    private string userName;
    public string UserName
    {
        get
        {
            if (userName == null)
            {
                userName = Membership.GetUser(this.UserID).UserName;
            }
            return userName;
        }
        set
        {
            userName = value;
        }
    }

    private string email;
    public string Email
    {
        get
        {
            if (email == null)
            {
                email = Membership.GetUser(this.UserID).Email;
            }
            return email;
        }
        set
        {
            email = value;
        }
    }

    private bool? isLockedOut;
    public bool? IsLockedOut
    {
        get
        {
            if (isLockedOut == null)
            {
                isLockedOut = Membership.GetUser(this.UserID).IsLockedOut;
            }
            return isLockedOut;
        }
        set
        {
            isLockedOut = value;
        }
    }
}
如果我这样做的话,我可以在管理员输入值时将它们传递回模型,并使用我自己的魔法来更新数据库中的只读字段,但我不确定是否以最佳方式实现了这个类

免责声明:我意识到最好的方法可能是建立一个定制的会员或个人资料提供商,但出于我无法控制的原因,我不能这样做。在所有这些示例中,我将从数据库中检索profile对象,该数据库已经从其成员记录链接了UserID

如果您对此有任何指示,我们将不胜感激。提前感谢您抽出时间来帮忙