It is a source code of youtube tutorial. MovieStoreMvc is a fullstack application which displays various movies along with there genres. A movie can have multiple genres. It is a good project for beginners, they can learn to develop fullstack app with authentication and also can learn many to many relationship.
- Visual Studio 2022
- .Net 6 (Now upgraded to .net 9.0)
- EF Core
- AspnetCore Identity
- SQL Server
-
clone the project
git clone https://github.com/rd003/MovieStoreMvc.git -
open
appsettings.jsonfile and update connection string'sdata source=your server name"ConnectionStrings": { "conn": "data source=your_server_name;initial catalog=MovieStoreMvc; integrated security=true;encrypt=false" } -
Open Tools > Package Manager > Package manager console
-
Run the command
update-database. -
Now you can run this project.
USE MovieStoreMvc;
GO
-- Insert Genres
INSERT INTO [dbo].[Genre] ([GenreName]) VALUES ('Action');
INSERT INTO [dbo].[Genre] ([GenreName]) VALUES ('Science Fiction');
INSERT INTO [dbo].[Genre] ([GenreName]) VALUES ('Drama');
INSERT INTO [dbo].[Genre] ([GenreName]) VALUES ('Comedy');
INSERT INTO [dbo].[Genre] ([GenreName]) VALUES ('Thriller');
GO
-- Insert Movies
INSERT INTO [dbo].[Movie] ([Title], [ReleaseYear], [MovieImage], [Cast], [Director])
VALUES ('Inception', '2010', 'inception.jpg', 'Leonardo DiCaprio, Joseph Gordon-Levitt, Ellen Page', 'Christopher Nolan');
GO
INSERT INTO [dbo].[Movie] ([Title], [ReleaseYear], [MovieImage], [Cast], [Director])
VALUES ('The Dark Knight', '2008', 'dark-knight.jpg', 'Christian Bale, Heath Ledger, Aaron Eckhart', 'Christopher Nolan');
GO
INSERT INTO [dbo].[Movie] ([Title], [ReleaseYear], [MovieImage], [Cast], [Director])
VALUES ('Parasite', '2019', 'parasite.jpg', 'Song Kang-ho, Lee Sun-kyun, Cho Yeo-jeong', 'Bong Joon-ho');
GO
INSERT INTO [dbo].[Movie] ([Title], [ReleaseYear], [MovieImage], [Cast], [Director])
VALUES ('The Grand Budapest Hotel', '2014', 'grand-budapest.jpg', 'Ralph Fiennes, Tony Revolori, Saoirse Ronan', 'Wes Anderson');
GO
INSERT INTO [dbo].[Movie] ([Title], [ReleaseYear], [MovieImage], [Cast], [Director])
VALUES ('Ex Machina', '2014', 'ex-machina.jpg', 'Alicia Vikander, Domhnall Gleeson, Oscar Isaac', 'Alex Garland');
GO
-- Insert MovieGenre relationships
-- Inception (Action, Sci-Fi, Thriller)
INSERT INTO [dbo].[MovieGenre] ([MovieId], [GenreId]) VALUES (1, 1); -- Action
INSERT INTO [dbo].[MovieGenre] ([MovieId], [GenreId]) VALUES (1, 2); -- Sci-Fi
INSERT INTO [dbo].[MovieGenre] ([MovieId], [GenreId]) VALUES (1, 5); -- Thriller
GO
-- The Dark Knight (Action, Drama, Thriller)
INSERT INTO [dbo].[MovieGenre] ([MovieId], [GenreId]) VALUES (2, 1); -- Action
INSERT INTO [dbo].[MovieGenre] ([MovieId], [GenreId]) VALUES (2, 3); -- Drama
INSERT INTO [dbo].[MovieGenre] ([MovieId], [GenreId]) VALUES (2, 5); -- Thriller
-- Parasite (Drama, Thriller)
INSERT INTO [dbo].[MovieGenre] ([MovieId], [GenreId]) VALUES (3, 3); -- Drama
INSERT INTO [dbo].[MovieGenre] ([MovieId], [GenreId]) VALUES (3, 5); -- Thriller
-- The Grand Budapest Hotel (Comedy, Drama)
INSERT INTO [dbo].[MovieGenre] ([MovieId], [GenreId]) VALUES (4, 4); -- Comedy
INSERT INTO [dbo].[MovieGenre] ([MovieId], [GenreId]) VALUES (4, 3); -- Drama
-- Ex Machina (Science Fiction, Drama, Thriller)
INSERT INTO [dbo].[MovieGenre] ([MovieId], [GenreId]) VALUES (5, 2); -- Sci-Fi
INSERT INTO [dbo].[MovieGenre] ([MovieId], [GenreId]) VALUES (5, 3); -- Drama
INSERT INTO [dbo].[MovieGenre] ([MovieId], [GenreId]) VALUES (5, 5); -- Thriller
- There is a controller
UserAuthenticationand a commented methodRegister. Uncomment theRegistermethod - Run the project and hit the url
https://localhost:7095/UserAuthentication/Register. You will be registered as a admin. Now you can re-comment the register user (for privacy). - Now you can login with credentials
Username: admin, password: Admin@123