Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Espen Solhaug #99

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
1 change: 1 addition & 0 deletions api-cinema-challenge/api-cinema-challenge.sln
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{3C371BAA-344D-4C8A-AF08-7829816D726F}"
ProjectSection(SolutionItems) = preProject
..\.gitignore = ..\.gitignore
api-cinema-challenge\ER Cinema Challenge.png = api-cinema-challenge\ER Cinema Challenge.png
..\README.md = ..\README.md
EndProjectSection
EndProject
Expand Down
13 changes: 13 additions & 0 deletions api-cinema-challenge/api-cinema-challenge/DTOs/CustomerDTO.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace api_cinema_challenge.DTOs
{
public class CustomerDTO
{
public int Id { get; set; }
public string Name { get; set; }
public string Phone { get; set; }
public string Email { get; set; }
public DateTime CreatedAt { get; set; }
public DateTime UpdatedAt { get; set; }

}
}
13 changes: 13 additions & 0 deletions api-cinema-challenge/api-cinema-challenge/DTOs/MovieDTO.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace api_cinema_challenge.DTOs
{
public class MovieDTO
{
public int Id { get; set; }
public string Title { get; set; }
public string Rating { get; set; }
public string Description { get; set; }
public int RuntimeMinutes { get; set; }
public DateTime CreatedAt { get; set; }
public DateTime UpdatedAt { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace api_cinema_challenge.DTOs.NestedDTOs
{
public class NestedScreeningDTO
{
public int ScreenNumber { get; set; }
public DateTime StartsAt { get; set; }
public int Capacity { get; set; }
public MovieDTO Movie { get; set; }
public DateTime CreatedAt { get; set; }
public DateTime UpdatedAt { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace api_cinema_challenge.DTOs.NestedDTOs
{
public class NestedTicketDTO
{
public int NumSeats { get; set; }
public CustomerDTO Customer { get; set; }
public NestedScreeningDTO Screening { get; set; }
public DateTime CreatedAt { get; set; }
public DateTime UpdatedAt { get; set; }
}
}
12 changes: 12 additions & 0 deletions api-cinema-challenge/api-cinema-challenge/DTOs/ScreeningDTO.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace api_cinema_challenge.DTOs
{
public class ScreeningDTO
{
public int Id { get; set; }
public int ScreenNumber { get; set; }
public int Capacity { get; set; }
public DateTime StartsAt { get; set; }
public DateTime CreatedAt { get; set; }
public DateTime UpdatedAt { get; set; }
}
}
20 changes: 20 additions & 0 deletions api-cinema-challenge/api-cinema-challenge/DTOs/TicketDTO.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
namespace api_cinema_challenge.DTOs
{
public class TicketDTO
{
public int Id { get; set; }
public int NumSeats { get; set; }
public CustomerDTO Customer { get; set; }
public ScreeningDTO Screening { get; set; }
public DateTime CreatedAt { get; set; }
public DateTime UpdatedAt { get; set; }
}

public class MinimalTicketDTO
{
public int Id { get; set; }
public int NumSeats { get; set; }
public DateTime CreatedAt { get; set; }
public DateTime UpdatedAt { get; set; }
}
}
10 changes: 8 additions & 2 deletions api-cinema-challenge/api-cinema-challenge/Data/CinemaContext.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
using Microsoft.EntityFrameworkCore;
using api_cinema_challenge.Models;
using Microsoft.EntityFrameworkCore;
using Newtonsoft.Json.Linq;

namespace api_cinema_challenge.Data
{
public class CinemaContext : DbContext
{
private string _connectionString;
public CinemaContext(DbContextOptions<CinemaContext> options) : base(options)
public CinemaContext()
{
var configuration = new ConfigurationBuilder().AddJsonFile("appsettings.json").Build();
_connectionString = configuration.GetValue<string>("ConnectionStrings:DefaultConnectionString")!;
Expand All @@ -22,5 +23,10 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
{

}

public DbSet<Customer> Customers { get; set; }
public DbSet<Movie> Movies { get; set; }
public DbSet<Screening> Screenings { get; set; }
public DbSet<Ticket> Tickets { get; set; }
}
}
49 changes: 49 additions & 0 deletions api-cinema-challenge/api-cinema-challenge/Data/Seeding.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using api_cinema_challenge.Models;

namespace api_cinema_challenge.Data
{
public static class Seeding
{
public async static void SeedDatabase(this WebApplication app)
{
using (var db = new CinemaContext())
{
if(!db.Customers.Any())
{
db.Add(new Customer() { Name = "Nigel", Phone = "40506070", Email = "[email protected]", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now });
db.Add(new Customer() { Name = "Dave", Phone = "60503020", Email = "[email protected]", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now });
db.Add(new Customer() { Name = "Sandro", Phone = "10206090", Email = "[email protected]", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now });
db.Add(new Customer() { Name = "Lisa", Phone = "40506070", Email = "[email protected]", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now });
await db.SaveChangesAsync();
}
if (!db.Movies.Any())
{
db.Add(new Movie() { Title = "Scream", Rating = "PG-16", Description = "Big Masks equals big entertainment", RuntimeMinutes = 115, CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now });
db.Add(new Movie() { Title = "Kill Bill", Rating = "PG-16", Description = "Big Swords equals big entertainment", RuntimeMinutes = 94, CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now });
db.Add(new Movie() { Title = "Moana", Rating = "PG-7", Description = "Large Waves equals large entertainment", RuntimeMinutes = 98, CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now });
await db.SaveChangesAsync();
}
if (!db.Screenings.Any())
{
db.Add(new Screening() { ScreenNumber = 1, StartsAt = DateTime.SpecifyKind(new DateTime(2025, 1, 30, 19, 30, 0), DateTimeKind.Utc), Capacity = 60, MovieId = 2, CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now });
db.Add(new Screening() { ScreenNumber = 2, StartsAt = DateTime.SpecifyKind(new DateTime(2025, 1, 30, 19, 30, 0), DateTimeKind.Utc), Capacity = 50, MovieId = 1, CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now });
db.Add(new Screening() { ScreenNumber = 3, StartsAt = DateTime.SpecifyKind(new DateTime(2025, 1, 30, 19, 30, 0), DateTimeKind.Utc), Capacity = 40, MovieId = 3, CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now });
db.Add(new Screening() { ScreenNumber = 1, StartsAt = DateTime.SpecifyKind(new DateTime(2025, 1, 31, 20, 30, 0), DateTimeKind.Utc), Capacity = 50, MovieId = 2, CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now });
await db.SaveChangesAsync();
}
if (!db.Tickets.Any())
{
db.Add(new Ticket() { NumSeats = 3, CustomerId = 1, ScreeningId = 2, });
db.Add(new Ticket() { NumSeats = 5, CustomerId = 2, ScreeningId = 1, });
db.Add(new Ticket() { NumSeats = 3, CustomerId = 3, ScreeningId = 3, });
db.Add(new Ticket() { NumSeats = 2, CustomerId = 4, ScreeningId = 4, });
db.Add(new Ticket() { NumSeats = 3, CustomerId = 2, ScreeningId = 3, });
db.Add(new Ticket() { NumSeats = 2, CustomerId = 2, ScreeningId = 4, });
await db.SaveChangesAsync();
}


}
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading