Skip to content

Commit

Permalink
Datenbank- und Razor-Komponenten-Updates
Browse files Browse the repository at this point in the history
.gitignore aktualisiert, um `UpdateDatabaseContextCommand.txt` hinzuzufügen.

Event-Klasse (`Event.cs`):
- Eigenschaften `Date` und `ImageLink` entfernt.
- Neue Sammlungen `EventsDateTimes` und `EventsExhibitorsApplies` hinzugefügt.

SamtWebsiteContext-Klasse (`SamtWebsiteContext.cs`):
- `DbSet`-Eigenschaften für `EventsDateTimes` und `EventsExhibitorsApply` hinzugefügt.
- `OnConfiguring`-Methode geändert, um Passwort aus Datei zu lesen.
- `EventsDateTime`-Entität in `OnModelCreating` konfiguriert.

Razor-Komponenten:
- `BringAndBuy.razor`: `currentEventId`-Initialisierung geändert.
- `Index.razor`, `Pricing.razor`, `Whenwhere.razor`, `NavMenu.razor`: `DbContext`-Initialisierungen entfernt und durch `CascadingParameter`-Eigenschaften ersetzt.
- `Index.razor`: Countdown-Logik angepasst.
- `Whenwhere.razor`: Anzeige der Event-Daten angepasst.
- `MainLayout.razor`: `DbContext`-Initialisierung hinzugefügt und `CascadingValue`-Komponenten um `NavMenu` und `Body` hinzugefügt.

Neue Datei `EventsDateTime.cs` hinzugefügt, die die `EventsDateTime`-Entität definiert.
  • Loading branch information
MarkenJaden committed Jul 11, 2024
1 parent b899307 commit ca89412
Show file tree
Hide file tree
Showing 10 changed files with 129 additions and 58 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
UpdateDatabaseContextCommand.txt

# Created by https://www.toptal.com/developers/gitignore/api/visualstudio,csharp,aspnetcore,dotnetcore
# Edit at https://www.toptal.com/developers/gitignore?templates=visualstudio,csharp,aspnetcore,dotnetcore
Expand Down
4 changes: 2 additions & 2 deletions Database/Models/Event.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ public partial class Event

public string Name { get; set; } = null!;

public DateTime Date { get; set; }

public string ImageLink { get; set; } = null!;

public int FkLocationId { get; set; }
Expand All @@ -25,6 +23,8 @@ public partial class Event

public virtual ICollection<EventsBringAndBuy> EventsBringAndBuys { get; set; } = new List<EventsBringAndBuy>();

public virtual ICollection<EventsDateTime> EventsDateTimes { get; set; } = new List<EventsDateTime>();

public virtual ICollection<EventsExhibitorsApply> EventsExhibitorsApplies { get; set; } = new List<EventsExhibitorsApply>();

public virtual ICollection<EventsShowactApply> EventsShowactApplies { get; set; } = new List<EventsShowactApply>();
Expand Down
19 changes: 19 additions & 0 deletions Database/Models/EventsDateTime.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;

namespace Database.Models;

public partial class EventsDateTime
{
public int Id { get; set; }

public int FkEventId { get; set; }

public DateOnly Date { get; set; }

public TimeOnly StartTime { get; set; }

public TimeOnly EndTime { get; set; }

public virtual Event FkEvent { get; set; } = null!;
}
27 changes: 25 additions & 2 deletions Database/Models/SamtWebsiteContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public SamtWebsiteContext(DbContextOptions<SamtWebsiteContext> options)

public virtual DbSet<EventsBringAndBuy> EventsBringAndBuys { get; set; }

public virtual DbSet<EventsDateTime> EventsDateTimes { get; set; }

public virtual DbSet<EventsExhibitorsApply> EventsExhibitorsApplies { get; set; }

public virtual DbSet<EventsShowactApply> EventsShowactApplies { get; set; }
Expand All @@ -50,7 +52,7 @@ public SamtWebsiteContext(DbContextOptions<SamtWebsiteContext> options)

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
#warning To protect potentially sensitive information in your connection string, you should move it out of source code. You can avoid scaffolding the connection string by using the Name= syntax to read it from configuration - see https://go.microsoft.com/fwlink/?linkid=2131148. For more guidance on storing connection strings, see https://go.microsoft.com/fwlink/?LinkId=723263.

Check warning on line 54 in Database/Models/SamtWebsiteContext.cs

View workflow job for this annotation

GitHub Actions / build

#warning: 'To protect potentially sensitive information in your connection string, you should move it out of source code. You can avoid scaffolding the connection string by using the Name= syntax to read it from configuration - see https://go.microsoft.com/fwlink/?linkid=2131148. For more guidance on storing connection strings, see https://go.microsoft.com/fwlink/?LinkId=723263.'

Check warning on line 54 in Database/Models/SamtWebsiteContext.cs

View workflow job for this annotation

GitHub Actions / build

#warning: 'To protect potentially sensitive information in your connection string, you should move it out of source code. You can avoid scaffolding the connection string by using the Name= syntax to read it from configuration - see https://go.microsoft.com/fwlink/?linkid=2131148. For more guidance on storing connection strings, see https://go.microsoft.com/fwlink/?LinkId=723263.'
=> optionsBuilder.UseMySql("server=landofrails.net;port=3306;user=samt;password=an1C_k/J/aw8yu2o;database=samt_website", Microsoft.EntityFrameworkCore.ServerVersion.Parse("10.6.18-mariadb"));
=> optionsBuilder.UseMySql($"server=landofrails.net;port=3306;user=samt;password={File.ReadAllText("sensitive-data")};database=samt_website", Microsoft.EntityFrameworkCore.ServerVersion.Parse("10.6.18-mariadb"));

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
Expand Down Expand Up @@ -162,7 +164,6 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
entity.Property(e => e.BringAndBuy)
.IsRequired()
.HasDefaultValueSql("'1'");
entity.Property(e => e.Date).HasColumnType("datetime");
entity.Property(e => e.FkLocationId)
.HasColumnType("int(11)")
.HasColumnName("FK_Location_ID");
Expand Down Expand Up @@ -196,6 +197,28 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
.HasConstraintName("Events_BringAndBuy_ibfk_1");
});

modelBuilder.Entity<EventsDateTime>(entity =>
{
entity.HasKey(e => e.Id).HasName("PRIMARY");

entity.ToTable("Events_DateTime");

entity.HasIndex(e => e.FkEventId, "FK_Event_ID");

entity.Property(e => e.Id)
.HasColumnType("int(11)")
.HasColumnName("ID");
entity.Property(e => e.EndTime).HasColumnType("time");
entity.Property(e => e.FkEventId)
.HasColumnType("int(11)")
.HasColumnName("FK_Event_ID");
entity.Property(e => e.StartTime).HasColumnType("time");

entity.HasOne(d => d.FkEvent).WithMany(p => p.EventsDateTimes)
.HasForeignKey(d => d.FkEventId)
.HasConstraintName("Events_DateTime_ibfk_1");
});

modelBuilder.Entity<EventsExhibitorsApply>(entity =>
{
entity.HasKey(e => e.Id).HasName("PRIMARY");
Expand Down
5 changes: 4 additions & 1 deletion SAMT-Website/Pages/BringAndBuy.razor
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,14 @@
bool generateButtonDisabled;
string number = "X";

[CascadingParameter]
public Event? _samt { get; set; }

protected override async Task OnAfterRenderAsync(bool firstRender)
{
context = await DbFactory.CreateDbContextAsync();

currentEventId = context.Events.OrderBy(x => x.Date).ToList().SkipWhile(x => x.Date <= DateTime.Now).First().Id.ToString();
currentEventId = _samt.Id.ToString();

Check warning on line 72 in SAMT-Website/Pages/BringAndBuy.razor

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.

if (await localStorage.ContainKeyAsync(currentEventId))
{
Expand Down
28 changes: 15 additions & 13 deletions SAMT-Website/Pages/Index.razor
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,8 @@
@using Database.Models
@using System.Globalization

@inject IDbContextFactory<SamtWebsiteContext> DbFactory
@inject IJSRuntime js

@{
var context = DbFactory.CreateDbContext();
var samt = context.Events.OrderBy(x => x.Date).Include(x => x.FkLocation).ToList().SkipWhile(x => x.Date <= DateTime.Now).FirstOrDefault();
}

<PageTitle>SAMT - Siegener Anime und Manga Treff</PageTitle>

<header class="bg-dark">
Expand All @@ -21,15 +15,15 @@
<div class="row pt-5">
<div class="col-md-8 col-xl-6 text-center text-md-start mx-auto" style="margin-top: -48px;">
<div class="text-center">
@if (samt is null)
@if (_samt is null)
{
<img class="img-fluid" src="https://i.imgur.com/D9jeMkR.png" width="300" alt="SAMT Logo">
<p class="mb-4" style="font-size: 1.6rem;">Coming soon... <br><span class="text-success"><strong>QwQ</strong></span><br> UwU</p>
}
else
{
<img class="img-fluid" src="@samt.ImageLink" width="300" alt="SAMT Logo">
<p class="mb-4" style="font-size: 1.6rem;">@samt.Name <br><span class="text-success"><strong>@samt.Date.ToString(CultureInfo.CurrentCulture.DateTimeFormat.LongDatePattern)</strong></span><br> @samt.FkLocation.Name</p>
<img class="img-fluid" src="@_samt.ImageLink" width="300" alt="SAMT Logo">
<p class="mb-4" style="font-size: 1.6rem;">@_samt.Name <br><span class="text-success"><strong>@_startDate.Date.ToDateTime(_startDate.StartTime).ToString(CultureInfo.CurrentCulture.DateTimeFormat.LongDatePattern)</strong></span><br> @_samt.FkLocation.Name</p>

Check warning on line 26 in SAMT-Website/Pages/Index.razor

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.
@if (!_days.Equals("00") || !_hours.Equals("00") || !_minutes.Equals("00") || !_seconds.Equals("00"))
{
<div class="row">
Expand Down Expand Up @@ -306,10 +300,17 @@
string _minutes = string.Empty;
string _seconds = string.Empty;

[CascadingParameter]
public Event? _samt { get; set; }

[CascadingParameter]
public EventsDateTime? _startDate { get; set; }

protected override void OnInitialized()
{
Countdown();
base.OnInitialized();

Countdown();
}

/**
Expand All @@ -322,16 +323,17 @@
async void Countdown()
{
// Obtain an instance of the DbContext through the DbFactory
var samt = (await DbFactory.CreateDbContextAsync()).Events.OrderBy(x => x.Date).ToList().SkipWhile(x => x.Date <= DateTime.Now).FirstOrDefault();
if (_startDate == null) return;
var samt = _startDate.Date.ToDateTime(_startDate.StartTime);

// The countdown will continue to loop until the event date is reached
while (samt is not null && samt.Date > DateTime.Now)
while (samt > DateTime.Now)
{
// Wait a second before updating the countdown
await Task.Delay(1000);

// Calculate the countdown time remaining
var countdown = samt.Date.Subtract(DateTime.Now);
var countdown = samt.Subtract(DateTime.Now);

// Update the properties representing the countdown values
_days = countdown.Days.ToString("D2");
Expand Down
19 changes: 9 additions & 10 deletions SAMT-Website/Pages/Pricing.razor
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,6 @@
@page "/ticket"
@page "/preise"
@using Database.Models
@using Microsoft.EntityFrameworkCore

@inject IDbContextFactory<SamtWebsiteContext> DbFactory

@{
var context = DbFactory.CreateDbContext();
var samt = context.Events.OrderBy(x => x.Date).Include(x => x.FkLocation).ToList().SkipWhile(x => x.Date <= DateTime.Now).FirstOrDefault();
}

<PageTitle>Preise</PageTitle>

Expand All @@ -31,7 +23,7 @@
<div>
<h3 class="fw-bold mb-0">Normaler Eintritt</h3>
<p>Für jeden</p>
<h4 class="display-4 fw-bold">@samt!.Price €</h4>
<h4 class="display-4 fw-bold">@_samt!.Price €</h4>
</div>
</div>
<div>
Expand Down Expand Up @@ -114,4 +106,11 @@
</div>
</div>
</div>
</section><!-- End: FAQ Preise -->
</section><!-- End: FAQ Preise -->

@code {

[CascadingParameter]
public Event? _samt { get; set; }

}
36 changes: 18 additions & 18 deletions SAMT-Website/Pages/Whenwhere.razor
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,6 @@
@page "/anfahrt"

@using Database.Models
@using Microsoft.EntityFrameworkCore

@inject IDbContextFactory<SamtWebsiteContext> DbFactory

@{
var context = DbFactory.CreateDbContext();
var samt = context.Events.OrderBy(x => x.Date).Include(x => x.FkLocation).ToList().SkipWhile(x => x.Date <= DateTime.Now).FirstOrDefault();
}

<PageTitle>Wann & Wo</PageTitle>

Expand All @@ -25,25 +17,28 @@
<div class="col-md-6 text-center text-md-start d-flex d-sm-flex d-md-flex justify-content-center align-items-center justify-content-md-start align-items-md-center justify-content-xl-end mb-4">
<div style="max-width: 450px;min-width: 422px;">
<p class="fw-bold text-success mb-2">Wann?</p>
@if (samt is null)
@if (_samt is null)
{
<h2 class="fw-bold">Kündigen wir bald an :3</h2>
}
else
{
<h2 class="fw-bold">@samt.Date.ToString("dd.MM.yyyy")</h2>
<p class="my-3"><strongffnungszeiten</strong><br>11:30 Uhr - 21:00 Uhr</p>
@foreach (var time in _samt.EventsDateTimes.OrderBy(x => x.Date))
{
<h2 class="fw-bold">@time.Date.ToString("dd.MM.yyyy")</h2>
<p class="my-3"><strongffnungszeiten</strong><br>@time.StartTime.ToString() Uhr - @time.EndTime.ToString() Uhr</p>
}
<p class="fw-bold text-success mb-2">Wo?</p>
<h2 class="fw-bold">@samt.FkLocation.Name</h2>
<p class="my-3">@samt.FkLocation.Street @samt.FkLocation.Number, @samt.FkLocation.Plz @samt.FkLocation.City</p>
<h2 class="fw-bold">@_samt.FkLocation.Name</h2>
<p class="my-3">@_samt.FkLocation.Street @_samt.FkLocation.Number, @_samt.FkLocation.Plz @_samt.FkLocation.City</p>
}
</div>
</div>
<div class="col-md-6 mb-4">
<div class="p-5 mx-lg-5" style="background: url(&quot;assets/img/blob.svg&quot;) center / contain no-repeat;">
@if (samt is not null)
@if (_samt is not null)
{
<iframe src="@samt.FkLocation.MapsLink" class="rounded img-fluid shadow w-100 fit-cover" style="border:0;min-height: 300px;" allowfullscreen="" loading="lazy" referrerpolicy="no-referrer-when-downgrade"></iframe>
<iframe src="@_samt.FkLocation.MapsLink" class="rounded img-fluid shadow w-100 fit-cover" style="border:0;min-height: 300px;" allowfullscreen="" loading="lazy" referrerpolicy="no-referrer-when-downgrade"></iframe>
}
</div>
</div>
Expand Down Expand Up @@ -75,9 +70,9 @@
<li>Frankfurt: RE 99/IC</li>
<li>Erndtebrück: Bus R27/RB 93/ RB 94</li>
</ul>
@if (samt is not null)
@if (_samt is not null)
{
<p class="text-muted card-text mb-4">Vom Bahnhof sind es noch ca. 8 Minuten (650 Meter) zu Fuß bis zur <strong>@samt.FkLocation.Name</strong>.</p>
<p class="text-muted card-text mb-4">Vom Bahnhof sind es noch ca. 8 Minuten (650 Meter) zu Fuß bis zur <strong>@_samt.FkLocation.Name</strong>.</p>
<a class="btn btn-primary btn-sm" role="button" href="assets/img/Wegbeschreibung_Bahnhof_BlueBox.jpeg" target="_blank">Karte Fußweg</a>
}
</div>
Expand Down Expand Up @@ -109,4 +104,9 @@
</div>
</div>
</div>
</section><!-- End: Barrierefreiheit -->
</section><!-- End: Barrierefreiheit -->
@code
{
[CascadingParameter]
public Event? _samt { get; set; }
}
29 changes: 26 additions & 3 deletions SAMT-Website/Shared/MainLayout.razor
Original file line number Diff line number Diff line change
@@ -1,7 +1,30 @@
@inherits LayoutComponentBase
@using Database.Models
@using Microsoft.EntityFrameworkCore
@inherits LayoutComponentBase

<NavMenu />
@inject IDbContextFactory<SamtWebsiteContext> DbFactory

@Body
<CascadingValue Value="Samt">
<CascadingValue Value="StartDate">
<NavMenu />
@Body
</CascadingValue>
</CascadingValue>

<Footer />

@code
{
EventsDateTime? StartDate;
Event? Samt;

protected override void OnInitialized()
{
base.OnInitialized();

var context = DbFactory.CreateDbContext();

StartDate = context.EventsDateTimes.OrderBy(x => x.Date).Include(x => x.FkEvent).ThenInclude(x => x.FkLocation).ToList().SkipWhile(x => x.Date.ToDateTime(x.StartTime) <= DateTime.Now).FirstOrDefault();
Samt = StartDate?.FkEvent;
}
}
19 changes: 10 additions & 9 deletions SAMT-Website/Shared/NavMenu.razor
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@
@using Microsoft.EntityFrameworkCore
@inject IDbContextFactory<SamtWebsiteContext> DbFactory

@{
var context = DbFactory.CreateDbContext();
var samt = context.Events.OrderBy(x => x.Date).Include(x => x.FkLocation).ToList().SkipWhile(x => x.Date <= DateTime.Now).FirstOrDefault();
var currentDate = DateOnly.FromDateTime(DateTime.Now);
}

<!-- Start: Navbar Centered Links -->
<nav class="navbar navbar-dark navbar-expand-md sticky-top navbar-shrink py-3" id="mainNav">
<div class="container-fluid">
Expand All @@ -26,11 +20,11 @@
@* </li> *@
<li class="nav-item"><NavLink ActiveClass="active" class="nav-link" href="anfahrt">Wann & Wo?</NavLink></li>
<li class="nav-item"><NavLink ActiveClass="active" class="nav-link" href="tickets">Tickets & Preise</NavLink></li>
@if (samt.BringAndBuy.Value)
@if (_samt.BringAndBuy.Value)

Check warning on line 23 in SAMT-Website/Shared/NavMenu.razor

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.

Check warning on line 23 in SAMT-Website/Shared/NavMenu.razor

View workflow job for this annotation

GitHub Actions / build

Nullable value type may be null.

Check warning on line 23 in SAMT-Website/Shared/NavMenu.razor

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.

Check warning on line 23 in SAMT-Website/Shared/NavMenu.razor

View workflow job for this annotation

GitHub Actions / build

Nullable value type may be null.
{
<li class="nav-item"><NavLink ActiveClass="active" class="nav-link" href="bnb">Bring & Buy</NavLink></li>
}
@if (samt is { ApplyOpen: not null, ApplyClose: not null } && currentDate >= samt.ApplyOpen.Value && currentDate <= samt.ApplyClose.Value)
@if (_samt is { ApplyOpen: not null, ApplyClose: not null } && _currentDate >= _samt.ApplyOpen.Value && _currentDate <= _samt.ApplyClose.Value)
{
<li class="nav-item dropdown">
<a class="dropdown-toggle nav-link" aria-expanded="true" data-bs-toggle="dropdown">Bewerbungen</a>
Expand All @@ -53,4 +47,11 @@
</a>
</div>
</div>
</nav><!-- End: Navbar Centered Links -->
</nav><!-- End: Navbar Centered Links -->
@code
{
[CascadingParameter]
public Event? _samt { get; set; }

DateOnly _currentDate = DateOnly.FromDateTime(DateTime.Now);
}

0 comments on commit ca89412

Please sign in to comment.