Models

As you know an MVC model is concerned with data

Models are .cs files that live in the MVC Models Folder

There are four models we need

  • Photo the base model that is the same as the SQL table
  • PhotoCreateViewModel used by the create form
  • PhotoEditViewModel used by the edit form
  • PhotoListViewModel used by the gallery display interface (for paging)

The Photo Model

    
        using System;
    using System.ComponentModel.DataAnnotations;
    using System.ComponentModel.DataAnnotations.Schema;

    [Table("Photo")]
    public partial class Photo
    {
        public int Id { get; set; }

        [StringLength(256)]
        public string Creator { get; set; }

        [StringLength(128)]
        public string SourceFilename { get; set; }

        [Required]
        [StringLength(4000)]
        public string Description { get; set; }

        [StringLength(400)]
        public string Keywords { get; set; }

        [StringLength(128)]
        public string AspNetUserID { get; set; }

        public byte? ForeignKeyTable { get; set; }

        [Column(TypeName = "smalldatetime")]
        public DateTime DateCreated { get; set; }

        [Column(TypeName = "smalldatetime")]
        public DateTime DateSaved { get; set; }

        public bool Flag { get; set; }

        public int Count { get; set; }
        
        public Guid GUID { get; set; }
    }

PhotoCreateViewModel


          public class PhotoCreateViewModel
    {
        [Required]
        public HttpPostedFileBase UploadedFile { get; set; } // for uploading the image

        [StringLength(256)]
        public string Creator { get; set; }

        [StringLength(128)]
        public string SourceFilename { get; set; }

        [Required]
        [StringLength(4000)]
        public string Description { get; set; }

        [StringLength(400)]
        public string Keywords { get; set; }

        [StringLength(128)]
        public string AspNetUserID { get; set; }

        public byte? ForeignKeyTable { get; set; }

    }
    

PhotoEditViewModel


         public class PhotoEditViewModel
    {
        public int Id { get; set; }

        [StringLength(256)]
        public string Creator { get; set; }

        [Required]
        [StringLength(4000)]
        public string Description { get; set; }

        [StringLength(400)]
        public string Keywords { get; set; }
        
        public bool Flag { get; set; }

    }
    

PhotoListViewModel


 public int Id { get; set; }

        [Required]
        [StringLength(256)]
        public string Creator { get; set; }

        [StringLength(128)]
        public string SourceFilename { get; set; }

        [StringLength(4000)]
        public string Description { get; set; }

        [StringLength(400)]
        public string Keywords { get; set; }

        [StringLength(128)]
        public string AspNetUserID { get; set; }

        public byte? ForeignKeyTable { get; set; }

        [Column(TypeName = "smalldatetime")]
        public DateTime DateCreated { get; set; }

        [Column(TypeName = "smalldatetime")]
        public DateTime DateSaved { get; set; }

        public bool Flag { get; set; }

        public int Count { get; set; }

        public Guid GUID { get; set; }

    }
    
Next >>>