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/Controllers/MoviesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public IActionResult Create()
// For more details, see http://go.microsoft.com/fwlink/?LinkId=317598.
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Create([Bind("Id,Title,Description,ReleaseDate,RatingId")] Movie movie)
public async Task<IActionResult> Create([Bind("Id,Title,Description,ReleaseDate,RatingId,ThumbnailURL")] Movie movie)
{
if (ModelState.IsValid)
{
Expand Down Expand Up @@ -91,7 +91,7 @@ public async Task<IActionResult> Edit(int? id)
// 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")] Movie movie)
public async Task<IActionResult> Edit(int id, [Bind("Id,Title,Description,ReleaseDate,RatingId,ThumbnailURL")] Movie movie)
{
if (id != movie.Id)
{
Expand Down
167 changes: 167 additions & 0 deletions CCMovieDatabase/Controllers/PorterListController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
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 PorterListController : Controller
{
private readonly MovieContext _context;

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

// GET: PorterList
public async Task<IActionResult> Index()
{
var movieContext = _context.Movie
.Include(m => m.Rating)
.Skip(2)
.Take(5);
return View(await movieContext.ToListAsync());
}

// GET: PorterList/Details/5
public async Task<IActionResult> Details(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);
}

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

// POST: PorterList/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: PorterList/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: PorterList/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: PorterList/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: PorterList/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);
}
}
}
12 changes: 9 additions & 3 deletions CCMovieDatabase/Data/MovieContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,21 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
{
new Rating { RatingId = 1, Name = "PG-13" },
new Rating { RatingId = 2, Name = "R" },
new Rating { RatingId = 3, Name = "G" }
new Rating { RatingId = 3, Name = "G" },
new Rating { RatingId = 4, Name = "PG" }
};
modelBuilder.Entity<Rating>().HasData(ratings);

// right here we seed data
var movies = new List<Movie>
{
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 },
new Movie { Id = 2, Title = "Shrek 2", ReleaseDate = new DateOnly(2002, 04, 26), Description = "Shrek is back baby!", RatingId = 1 },
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 = "Harry Potter and the Sorcerer's Stone", ReleaseDate = new DateOnly(2001,01,01), Description = "An orphaned boy enrolls in a school of wizardry, where he learns the truth about himself, his family and the terrible evil that haunts the magical world.", RatingId = 4, ThumbnailURL = "https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcQcZT3sdwr1NiJytvJb95icJJKPWpWRNv35l_uuVYxjlzBJS-hb" },
new Movie { Id = 4, Title = "Toy Story", ReleaseDate = new DateOnly(1995,01,01), Description = "A cowboy doll is profoundly jealous when a new spaceman action figure supplants him as the top toy in a boy's bedroom.", RatingId = 3, ThumbnailURL = "https://m.media-amazon.com/images/M/MV5BZTA3OWVjOWItNjE1NS00NzZiLWE1MjgtZDZhMWI1ZTlkNzYwXkEyXkFqcGc@._V1_.jpg" },
new Movie { Id = 5, Title = "A Christmas Story", ReleaseDate = new DateOnly(1983,01,01), Description = "In the 1940s, a young boy named Ralphie Parker attempts to convince his parents, teacher, and Santa Claus that a Red Ryder Range 200 Shot BB gun really is the perfect Christmas gift.", RatingId = 4, ThumbnailURL = "https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcSUZk92ju8kisZKCc9m4lyySg9S5RSM6mhFnSWOpOb1_MlCsHsw" },
new Movie { Id = 6, Title = "Elf", ReleaseDate = new DateOnly(2003,01,01), Description = "Raised as an oversized elf, Buddy travels from the North Pole to New York City to meet his biological father, Walter Hobbs, who doesn't know he exists and is in desperate need of some Christmas spirit.", RatingId = 4, ThumbnailURL = "https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcT08ZFpbAwAL_jQFtQfMjut1_T6oNgxRCQiOPA6S1twJLXZq_Wi" },
new Movie { Id = 7, Title = "Weapons", ReleaseDate = new DateOnly(2025,01,01), Description = "When all but one child from the same class mysteriously vanish on the same night at exactly the same time, a community is left questioning who or what is behind their disappearance.", RatingId = 2, ThumbnailURL = "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcR84Bm2XnTfW7hukdkEdr5jezVGfoIt22h0-s7Dfk1aRavoPZmh" }

};

Expand Down
Loading