Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CCMovieDatabase/CCMovieDatabase.csproj.user
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<WebStackScaffolding_IsAsyncSelected>False</WebStackScaffolding_IsAsyncSelected>
<WebStackScaffolding_IsViewGenerationSelected>True</WebStackScaffolding_IsViewGenerationSelected>
<WebStackScaffolding_ViewDialogWidth>650</WebStackScaffolding_ViewDialogWidth>
<Controller_SelectedScaffolderID>ApiControllerEmptyScaffolder</Controller_SelectedScaffolderID>
<Controller_SelectedScaffolderCategoryPath>root/Common/Api</Controller_SelectedScaffolderCategoryPath>
<Controller_SelectedScaffolderID>MvcControllerWithContextScaffolder</Controller_SelectedScaffolderID>
<Controller_SelectedScaffolderCategoryPath>root/Common/MVC/Controller</Controller_SelectedScaffolderCategoryPath>
</PropertyGroup>
</Project>
175 changes: 175 additions & 0 deletions CCMovieDatabase/Controllers/ChristianListController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.EntityFrameworkCore;
using CCMovieDatabase.Data;
using CCMovieDatabase.Models;

namespace CCMovieDatabase.Controllers
{
public class ChristianListController : Controller
{
private readonly MovieContext _context;

public ChristianListController(MovieContext context)
{
_context = context;
}

// GET: ChristianList
public async Task<IActionResult> Index()
{

int[] myMovieIds = { 3, 4, 5, 6, 7 };

var myMovies = await _context.Movie
.Where(m => myMovieIds.Contains(m.Id))
.ToListAsync();

var movieContext = _context.Movie.Include(m => m.Rating);
return View(await movieContext.ToListAsync());
return View(myMovies);
}

// GET: ChristianList/Details/5
public async Task<IActionResult> Details(int? id)
{

int[] myMovieIds = { 3, 4, 5, 6, 7 };

if (id == null || !myMovieIds.Contains(id.Value))
{
return NotFound();
}

var movie = await _context.Movie
.Include(m => m.Rating)
.FirstOrDefaultAsync(m => m.Id == id);
if (movie == null)
{
return NotFound();
}

return View(movie);
}

// GET: ChristianList/Create
public IActionResult Create()
{
ViewData["RatingId"] = new SelectList(_context.Ratings, "RatingId", "RatingId");
return View();
}

// POST: ChristianList/Create
// To protect from overposting attacks, enable the specific properties you want to bind to.
// For more details, see http://go.microsoft.com/fwlink/?LinkId=317598.
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Create([Bind("Id,Title,Description,ReleaseDate,RatingId,ThumbnailURL")] Movie movie)
{
if (ModelState.IsValid)
{
_context.Add(movie);
await _context.SaveChangesAsync();
return RedirectToAction(nameof(Index));
}
ViewData["RatingId"] = new SelectList(_context.Ratings, "RatingId", "RatingId", movie.RatingId);
return View(movie);
}

// GET: ChristianList/Edit/5
public async Task<IActionResult> Edit(int? id)
{
if (id == null)
{
return NotFound();
}

var movie = await _context.Movie.FindAsync(id);
if (movie == null)
{
return NotFound();
}
ViewData["RatingId"] = new SelectList(_context.Ratings, "RatingId", "RatingId", movie.RatingId);
return View(movie);
}

// POST: ChristianList/Edit/5
// To protect from overposting attacks, enable the specific properties you want to bind to.
// For more details, see http://go.microsoft.com/fwlink/?LinkId=317598.
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Edit(int id, [Bind("Id,Title,Description,ReleaseDate,RatingId,ThumbnailURL")] Movie movie)
{
if (id != movie.Id)
{
return NotFound();
}

if (ModelState.IsValid)
{
try
{
_context.Update(movie);
await _context.SaveChangesAsync();
}
catch (DbUpdateConcurrencyException)
{
if (!MovieExists(movie.Id))
{
return NotFound();
}
else
{
throw;
}
}
return RedirectToAction(nameof(Index));
}
ViewData["RatingId"] = new SelectList(_context.Ratings, "RatingId", "RatingId", movie.RatingId);
return View(movie);
}

// GET: ChristianList/Delete/5
public async Task<IActionResult> Delete(int? id)
{
if (id == null)
{
return NotFound();
}

var movie = await _context.Movie
.Include(m => m.Rating)
.FirstOrDefaultAsync(m => m.Id == id);
if (movie == null)
{
return NotFound();
}

return View(movie);
}

// POST: ChristianList/Delete/5
[HttpPost, ActionName("Delete")]
[ValidateAntiForgeryToken]
public async Task<IActionResult> DeleteConfirmed(int id)
{
var movie = await _context.Movie.FindAsync(id);
if (movie != null)
{
_context.Movie.Remove(movie);
}

await _context.SaveChangesAsync();
return RedirectToAction(nameof(Index));
}

private bool MovieExists(int id)
{
return _context.Movie.Any(e => e.Id == id);
}
}
}
6 changes: 6 additions & 0 deletions CCMovieDatabase/Data/MovieContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
{
new Movie { Id = 1, Title = "Shrek", ReleaseDate = new DateOnly(2001, 04, 26), Description = "A mean lord exiles fairytale creatures to the swamp of a grumpy ogre, who must go on a quest and rescue a princess for the lord in order to get his land back.", RatingId = 1, ThumbnailURL = "https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcTG_q0A0cypAsXxYlgs5J_554BrcnjeeKExlQE3ZaZUuPYv0fUd" },
new Movie { Id = 2, Title = "Shrek 2", ReleaseDate = new DateOnly(2002, 04, 26), Description = "Shrek is back baby!", RatingId = 1, ThumbnailURL = "https://encrypted-tbn3.gstatic.com/images?q=tbn:ANd9GcTPx7lW6h0G1O9-npEnVPL07fT74Tp6SFl0i47nxfypyVBcQFdS" },
new Movie { Id = 3, Title = "Austin Powers: International Man of Mystery", ReleaseDate = new DateOnly(1997, 05, 02), Description = "A world-class playboy and part-time secret agent from the 1960s emerges after thirty years in a cryogenic state to battle with his nemesis Dr. Evil.", RatingId = 1, ThumbnailURL = "https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcTlO5X0VeATdsHkdAiSqrIjnibxUZFxHvr56dYDONVdRyNsdJyhhAgLl7cMeUZX_nJL1szd1r0PWHMyHtWNoVVvP1FZNLZ6-A"},
new Movie { Id = 4, Title = "Austin Powers: The Spy Who Shagged Me", ReleaseDate = new DateOnly(1999, 06, 11), Description = "Dr. Evil is back and has invented a new time machine that allows him to go back to the 1960s and steal Austin Powers' mojo, inadvertently leaving him \"shagless\".", RatingId = 1, ThumbnailURL = "https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcSIfeD5mGXpWtcfJ_ycbhE_9ZAqnEugZyaEOd9vnjZYPipvpQq2olg1Bl2uyE6N_VcV7L0cnGIGgg8WqQD-fRo-USv7_4lLeQ" },
new Movie { Id = 5, Title = "Austin Powers in Goldmember", ReleaseDate = new DateOnly(2002, 07, 26), Description = "Upon learning that his father has been kidnapped, Austin Powers must travel to 1975 and defeat the aptly named villain Goldmember, who is working with Dr. Evil.", RatingId = 1, ThumbnailURL = "https://static.qobuz.com/images/covers/66/49/0081227784966_600.jpg" },
new Movie { Id = 6, Title = "Five Nights at Freddy's", ReleaseDate = new DateOnly(2023, 10, 27), Description = "A troubled security guard begins working at Freddy Fazbear's Pizza. During his five nights on the job, he realizes that something is wrong with the pizzeria and pretty soon finds the truth about its animatronics.", RatingId = 1, ThumbnailURL = "https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcTaydvBSSHZ_qYRr2QlfuisPN1JxzqmasvFmmuhCn9-vLzw6D1cY7NXscySkTHC80g2ASZKzSi2ATEICdak16TVc_kxIkeXFA" },
new Movie { Id = 7, Title = "Five Nights ar Freddy's 2", ReleaseDate = new DateOnly(2025, 12, 05), Description = "Anyone can survive five nights. This time, there will be no second chances.", RatingId = 1, ThumbnailURL = "https://encrypted-tbn3.gstatic.com/images?q=tbn:ANd9GcQlGcWZganGfskXyYsVD1UMZmtaXp2y7nlxqJlWXAkAMSRYG6QgGZ-OCUAt77g7EC5Md-gD-7Ht8mV2OKFLj-nPQjUPW5a9DA"
}
};

modelBuilder.Entity<Movie>().HasData(movies);
Expand Down
Loading