Add temp movie data

Let us add some data to display

Creating temporary data

Ideally, we get data from some data store like database or service. For this discussion let us keep database or ORM specific details away and rather create a fake Context, which will serve as a data source for now. We can later replace it with a real data context!

ORMs use the term Context to denote an object which is an interface with the application code and the underlying database. Context objects do the heavy lifting for us and we can focus on the data itself.

Adding a fake context

Let us first create a folder called Data at the root of the project and then create a class called FakeContext.cs inside the data folder, as shown:

Replace the contents of FakeContext.cs class with this:

using MvcMovie.Models;
using System.Collections.Generic;

namespace MvcMovie.Data
{
    public class FakeContext
    {
        public List<Movie> Movie { get; set; }
        public FakeContext()
        {
            Movie = new List<Movie>()
            {
                new Movie
                {
                    Id = 1,
                    Title = "Avatar: The way of water",
                    ReleaseDate = DateTime.Parse("2022,12,25"),
                    Genre = "Fiction",
                    Price = 49.99M
                },
                new Movie
                {
                    Id = 2,
                    Title = "Titanic",
                    ReleaseDate = DateTime.Parse("1997,01,01"),
                    Genre = "Drama",
                    Price = 99.99M
                }
            };
        }
    }
}

Let us see how to pass the data from controller to view next!

Last updated