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
5 changes: 5 additions & 0 deletions CCMovieDatabase/CCMovieDatabase.csproj.user
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,10 @@
<WebStackScaffolding_DbContextTypeFullName>CCMovieDatabase.Data.MovieContext</WebStackScaffolding_DbContextTypeFullName>
<WebStackScaffolding_IsAsyncSelected>False</WebStackScaffolding_IsAsyncSelected>
<WebStackScaffolding_IsViewGenerationSelected>True</WebStackScaffolding_IsViewGenerationSelected>
<Controller_SelectedScaffolderID>MvcControllerEmptyScaffolder</Controller_SelectedScaffolderID>
<Controller_SelectedScaffolderCategoryPath>root/Common/MVC/Controller</Controller_SelectedScaffolderCategoryPath>
<View_SelectedScaffolderID>RazorViewEmptyScaffolder</View_SelectedScaffolderID>
<View_SelectedScaffolderCategoryPath>root/Common/MVC/View</View_SelectedScaffolderCategoryPath>
<WebStackScaffolding_ViewDialogWidth>650</WebStackScaffolding_ViewDialogWidth>
</PropertyGroup>
</Project>
158 changes: 158 additions & 0 deletions CCMovieDatabase/Controllers/JamelController2.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
using CCMovieDatabase.Data;
using CCMovieDatabase.Models;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.EntityFrameworkCore;

namespace CCMovieDatabase.Controllers
{
public class JamelController2 : Controller
{
private readonly MovieContext _context;
// i tried to seperate the description and titles into 2 seperate pages and it did not work
// im keeping all the code here to show my thought process

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

public async Task<IActionResult> Index2()
{
var movieContext = _context.Movie.Include(m => m.Description);
return View(await movieContext.ToListAsync());
}


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);
}


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

[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Create([Bind("Id,Title,Description,ReleaseDate,RatingId")] 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);
}


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);
}


[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Edit(int id, [Bind("Id,Title,Description,ReleaseDate,RatingId")] 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);
}


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);
}

[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);
}
}


}

166 changes: 166 additions & 0 deletions CCMovieDatabase/Controllers/JamelsController1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
using CCMovieDatabase.Data;
using CCMovieDatabase.Models;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.EntityFrameworkCore;

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

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

// i could not figure out how to only display movies and descriptions separately so I put into comments the code I wrote that did not work
// the titles and descriptions show up but i could not get them separately
public async Task<IActionResult> Index()
{
var movieContext = _context.Movie.Include(m => m.Rating);
return View(await movieContext.ToListAsync());

//var movieContext = _context.Movie.Include(m => m.Title);
//return View(await movieContext.ToListAsync());

}
// this code works
public async Task<IActionResult> Index2()
{
var movieContext = _context.Movie.Include(m => m.Description);
return View(await movieContext.ToListAsync());
}


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);
}


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

[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Create([Bind("Id,Title,Description,ReleaseDate,RatingId")] 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);
}


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);
}


[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Edit(int id, [Bind("Id,Title,Description,ReleaseDate,RatingId")] 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);
}


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);
}

[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);
}
}
}

7 changes: 7 additions & 0 deletions CCMovieDatabase/Data/MovieContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,17 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
modelBuilder.Entity<Rating>().HasData(ratings);

// right here we seed data
// im not a big movie guy so I ran out of movie ideas
// I also made the descriptions myself as I really like all these shows and movies
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 = 3, Title = "Sonic 3", ReleaseDate = new DateOnly(2024, 12, 20), Description = "The third sonic movie focusing on shadow and the sonic adventure 2 inspired story", RatingId = 1 },
new Movie { Id = 4, Title = "Star Wars Revenge of ths sith", ReleaseDate = new DateOnly(2005, 04, 26), Description = "The final movie in the prequel trilogy connecting it to the original trilogy", RatingId = 1 },
new Movie { Id = 5, Title = "Avatar the last airbender", ReleaseDate = new DateOnly(2005, 02, 21), Description = "about the avatar a supposed master of the 4 bending elements ", RatingId = 1 },
new Movie { Id = 6, Title = "Frieren: Beyond Journeys ENd", ReleaseDate = new DateOnly(2023, 09, 29), Description = "about an immortal elf that goes on an adventure to understand the meaning of the limited time poeple have", RatingId = 1 },
new Movie { Id = 7, Title = "The Mario Movie", ReleaseDate = new DateOnly(2023, 04, 05), Description = "The mario movie giving a diffrent story of how Mario came to the Mushroom kingdom", RatingId = 1 },

};

Expand Down
Loading