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
2 changes: 1 addition & 1 deletion CCMovieDatabase/CCMovieDatabase.csproj.user
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<WebStackScaffolding_DbContextDialogWidth>650</WebStackScaffolding_DbContextDialogWidth>
<WebStackScaffolding_IsLayoutPageSelected>True</WebStackScaffolding_IsLayoutPageSelected>
<WebStackScaffolding_IsPartialViewSelected>False</WebStackScaffolding_IsPartialViewSelected>
<WebStackScaffolding_IsReferencingScriptLibrariesSelected>False</WebStackScaffolding_IsReferencingScriptLibrariesSelected>
<WebStackScaffolding_IsReferencingScriptLibrariesSelected>True</WebStackScaffolding_IsReferencingScriptLibrariesSelected>
<WebStackScaffolding_LayoutPageFile />
<WebStackScaffolding_DbContextTypeFullName>CCMovieDatabase.Data.MovieContext</WebStackScaffolding_DbContextTypeFullName>
<WebStackScaffolding_IsAsyncSelected>False</WebStackScaffolding_IsAsyncSelected>
Expand Down
170 changes: 170 additions & 0 deletions CCMovieDatabase/Controllers/AedonController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
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;
//I'm not sure if i did this correctly however this is my attempt and hopefully i didnt mess up too badly

namespace CCMovieDatabase.Controllers
{

public class AedonController : Controller
{
private readonly MovieContext _context;

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

// GET: Aedon
public async Task<IActionResult> Index()
{
//exclude shrek 1 and shrek 2
var movieContext = _context.Movie.Include(m => m.Rating)
.Where(m => m.Title != "Shrek")
.Where(m => m.Title != "Shrek 2");
return View(await movieContext.ToListAsync());
}

// GET: Aedon/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: Aedon/Create
public IActionResult Create()
{
ViewData["RatingId"] = new SelectList(_context.Ratings, "RatingId", "RatingId");
return View();
}

// POST: Aedon/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: Aedon/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: Aedon/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: Aedon/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: Aedon/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: 11 additions & 1 deletion CCMovieDatabase/Data/MovieContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);


var ratings = new List<Rating>
{
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);

Expand All @@ -42,6 +44,14 @@ 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" },

//Aedon seed data

new Movie { Id = 3, Title = "Army of Darkness", ReleaseDate = new DateOnly(1993, 02, 19), Description = "When Ash Williams is accidentally transported to 1300 A.D., he must retrieve the Necronomicon and battle an army of the dead in order to return home.", RatingId = 2, ThumbnailURL = "https://external-content.duckduckgo.com/iu/?u=http%3A%2F%2Fwww.impawards.com%2F1993%2Fposters%2Farmy_of_darkness_ver3.jpg&f=1&nofb=1&ipt=0f5ba9f7dec46adcdb32748f094b542e4b5c8eff313c6811ef1bea9fde96af7d" },
new Movie { Id = 4, Title = "The Truman Show", ReleaseDate = new DateOnly(1998, 06, 05), Description = "An insurance salesman begins to suspect that his whole life is actually some sort of reality TV show.", RatingId = 4, ThumbnailURL = "https://external-content.duckduckgo.com/iu/?u=https%3A%2F%2Fpostertok.com%2Fwp-content%2Fuploads%2F2024%2F02%2F5337.webp&f=1&nofb=1&ipt=0e1573f1b1d07b5daa12a781e53f49b27c130790c4d2dcde54916cc0eff9f901" },
new Movie { Id = 5, Title = "The Cable Guy", ReleaseDate = new DateOnly(1996, 06, 14), Description = "A designer makes a grievous mistake when he rejects the friendship of a borderline cable guy.", RatingId = 1, ThumbnailURL = "https://external-content.duckduckgo.com/iu/?u=https%3A%2F%2Fc8.alamy.com%2Fcomp%2FBKG4ED%2Fthe-cable-guy-1996-poster-BKG4ED.jpg&f=1&nofb=1&ipt=04d76ad2b1e8ab66bd02da1ce264a9d679f0f2cad012d7c99c0ac192572af20b" },
new Movie { Id = 6, Title = "Spider-Man", ReleaseDate = new DateOnly(2002, 05, 03), Description = "After being bitten by a genetically-modified spider, a shy teenager gains spider-like abilities that he uses to fight injustice as a masked superhero and face a vengeful enemy.", RatingId = 1, ThumbnailURL = "https://external-content.duckduckgo.com/iu/?u=https%3A%2F%2Famc-theatres-res.cloudinary.com%2Fv1579117618%2Famc-cdn%2Fproduction%2F2%2Fmovies%2F3500%2F3499%2FPoster%2Fp_800x1200_Spider-Man_En_0802517.jpg&f=1&nofb=1&ipt=a5788d911cca9535bbb702afd5665df889150246b214e4f0394fc6f0a1e6f798" },
new Movie { Id = 7, Title = "The Nightmare Before Christmas", ReleaseDate = new DateOnly(1993, 10, 29), Description = "Jack Skellington, king of Halloween Town, discovers Christmas Town, but his attempts to bring Christmas to his home causes confusion.", RatingId = 4, ThumbnailURL = "https://external-content.duckduckgo.com/iu/?u=http%3A%2F%2Fwww.impawards.com%2F1993%2Fposters%2Fnightmare_before_christmas_ver1.jpg&f=1&nofb=1&ipt=a3fc758eba9bddd233e7d4e35b4511f5d2f2482e2d85d1589232c9d6a4c4efe6" },
};

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