0

我在我的 ASP.NET MVC4 Web 应用程序中定义了一个练习实体。我正在使用带有默认 AccountModels.cs 类的表单身份验证。

我的课看起来像

public class Exercise
    {

        private DateTime _DateCreated = DateTime.Now;
        private UserProfile _Teacher;
        public int Id{ get; set; }
        public string Question { get; set; }
        public int Anwser { get; set; }
        public string Category { get; set; }
        public int maxNbrOfAttempts { get; set; }
        public string Hints { get; set; }
        public virtual ICollection<Quiz> Quizzes { get; set; }

        public DateTime Date
        {
            get { return _DateCreated; }
            set { _DateCreated = value; }
        }

        public UserProfile Author
        {
            get { return _Teacher; }
            set { _Teacher = value; }
        }

    }

我是否正确使用 UserProfile 在练习和登录用户之间建立链接?如何在我的控制器中获取当前的 UserProfile?

4

1 回答 1

0

像这样改变它:

public class Exercise
{
    public Exercise()
    {
        this.Date = DateTime.Now;
        this.Author = User.Identity.Name; //Write this line if you want to set
                                          //the currently logged in user as the Author
    public int Id{ get; set; }
    public string Question { get; set; }
    public int Anwser { get; set; }
    public string Category { get; set; }
    public int maxNbrOfAttempts { get; set; }
    public string Hints { get; set; }

    public virtual ICollection<Quiz> Quizzes { get; set; }

    public virtual DateTime Date { get; set; }        
    public virtual UserProfile Author { get; set; }         
}
于 2013-08-17T13:01:50.577 回答