I have been searching around and really can not find a decent answer on how to build a ViewModel and then fill that with the data from my EF model. The two EF models I want to push into a single ViewModel are:
public class Section
{
[DatabaseGenerated(DatabaseGeneratedOption.Identity), HiddenInput]
public Int16 ID { get; set; }
[HiddenInput]
public Int64? LogoFileID { get; set; }
[Required, MaxLength(250), Column(TypeName = "varchar"), DisplayName("Route Name")]
public string RouteName { get; set; }
[Required, MaxLength(15), Column(TypeName = "varchar")]
public string Type { get; set; }
[Required]
public string Title { get; set; }
[HiddenInput]
public string Synopsis { get; set; }
[ForeignKey("LogoFileID")]
public virtual File Logo { get; set; }
}
public class File
{
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public Int64 ID { get; set; }
[Required, MaxLength(60), Column(TypeName = "varchar")]
public string FileName { get; set; }
[Required, MaxLength(50), Column(TypeName = "varchar")]
public string ContentType { get; set; }
}
And I would like to build a ViewModel that looks like:
public class SectionViewMode
{
public Int16 SectionID { get; set; }
public bool HasLogo { get; set; } //Set to True if there is a FileID found for the section
public string Type { get; set; }
public string Title { get; set; }
public string Synopsis { get; set; }
}
I would assume it would be best to create a constructor method in the ViewModel so when NEW
is called on it the data is filled but what I can not seem to find or figure out is how I go about filling that data.