Model
- Create Objects to represent the classes
namespace PhotoSharingApplication.Models
{
public class Photo
{
public int PhotoID { get; set; }
public string Title { get; set; }
public byte[] PhotoFile
{ get; set; }
public string ImageMimeType
{ get; set; }
public string Description
{ get; set; }
public DateTime CreatedDate
{ get; set; }
public string UserName
{ get; set; }
- Create the relationship
public virtual ICollection<Comment>
Comments { get; set; }
}
}
- Comments - Second class
namespace PhotoSharingApplication.Models
{
public class Comment
{
public int CommentID { get; set; }
public int PhotoID { get; set; }
public string UserName
{ get; set; }
public string Subject { get; set; }
public string Body { get; set; }
- Create the relationship
public virtual Photo Photo
{ get; set; }
}
}
Adding validations and changes for the view
public class Photo
{
[Required]
public int PhotoID { get; set; }
public string Title { get; set; }
[DisplayName("Picture")]
public byte[] PhotoFile
{ get; set; }
[DataType(DataType.MultilineText)]
public string ImageMimeType
{ get; set; }
[DataType(DataType.DateTime)]
[DisplayName("Created Date")]
[DisplayFormat(DataFormatString =
"{0:MM/dd/yy}")]
public string Description
{ get; set; }
public DateTime CreatedDate
{ get; set; }
public string UserName
{ get; set; }
public virtual ICollection<Comment>
Comments { get; set; }
}
Comment
public class Comment
{
public int CommentID { get; set; }
public int PhotoID { get; set; }
public string UserName
{ get; set; }
[Required]
[StringLength(250)]
public string Subject { get; set; }
[DataType(DataType.MultilineText)]
public string Body { get; set; }
public virtual Photo Photo
{ get; set; }
}
Comentarios
Publicar un comentario