title: ASP.NET MVC - create a new Model or use a Entity framework class
body: <p>I am developing a ASP.NET MVC 3 application, i am using entity framework code first in order to create the classes of my app, and i also have a repository in order to perform the operations on it, keeping clean the DBContext and the DBEntities definitions.</p>
  
  <p>My doubt is about the render of the views and the way where a edit model is saved.</p>
  
  <p>If I have this entity that represent a user stored in my DB:</p>
  
  <pre><code>//Entity:
  public class User 
  {
      [Key]
      public int IdUser { get; set; }
      public string UserName { get; set; }   
      public string Password { get; set; }
      public string FirstName { get; set; }
      public string LastName { get; set; }
      public string Email { get; set; }
  }
  </code></pre>
  
  <p>And i want to show a View with the FirstName, LastName, Email and NewPassword, ConfirmPasword and CurrentPassword,  in order to let the user change his data, typing the CurrentPassword to confirm the changes, so my doubt is, fieds like ConfirmPasword and CurrentPassword aren´t in my entity so i need to create a new model for this View and the copy the information that i want from my new Model to my database entity in order to save it? Like:</p>
  
  <pre><code>public class UpdateUserModel
  {
  
      [Required]
      [Display(Name = "Name")]
      public string FirstName{ get; set; }
  
      [Required]
      [Display(Name = "Last Name")]
      public string LastName{ get; set; }
  
      [Required]
      [DataType(DataType.EmailAddress)]
      [Display(Name = "Not valid email")]
      public string Email { get; set; }      
  
      [DataType(DataType.Password)]
      [Display(Name = "New password")]
      public string NewPasword{ get; set; }
  
      [DataType(DataType.Password)]
      [Display(Name = "Confirm the New Pasword")]
      [Compare("NewPasword", ErrorMessage = "Password doesn´t mach.")]
      public string ConfirmPasword{ get; set; }
  
      [Required(ErrorMessage = "Need to specify the current password to save changes")]
      [DataType(DataType.Password)]
      [Display(Name = "Current Password")]
      public string CurrentPassword { get; set; }
  }
  </code></pre>
  
  <p>and in the controller i made:</p>
  
  <pre><code>public ActionResult UpdateUser(UpdateUserModel model)
  {              
      User u = (User)Membership.GetUser();            
      u.FirstName = model.FirstName;
      u.LastName = model.LastName;
      u.Email = model.Email;
  
      if (!String.IsNullOrEmpty(model.NewPassword))
      {
          u.Password = FormsAuthentication.HashPasswordForStoringInConfigFile(model.NewPassword.Trim(), "md5");
      }
  
      repository.UpdateUser(u);
  
      return View();
  }
  </code></pre>
  
  <p>There are any way of doing this having a controller like:</p>
  
  <pre><code>public ActionResult UpdateUser(User u)
  {               
      repository.UpdateUser(u);              
      return View();
  }
  </code></pre>
  
  <p>Because if i have that, how i can add the field like, ConfirmPassword or CurrentPassword in order to made the validation for this specific View.</p>