Compare commits
18 Commits
663b6b03ea
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 762680537b | |||
| dbcd9f4872 | |||
| 18289006d1 | |||
| d90a6f970f | |||
| 4634c4ae98 | |||
| 7afab94810 | |||
| b82ff1bce3 | |||
| 6e8e16757f | |||
| 1c81d28cfd | |||
| 9cb299706d | |||
| 530e79d581 | |||
| 291cc195b1 | |||
| 7f99284809 | |||
| 6afbb807a1 | |||
| ab117c263d | |||
| 6575fc1d60 | |||
| c290a3af0a | |||
| e285270621 |
@@ -28,11 +28,11 @@ jobs:
|
|||||||
- name: Buildah Build
|
- name: Buildah Build
|
||||||
run: |
|
run: |
|
||||||
buildah build -t ${{ github.sha }} ./Einheit_4/2025_5BHITN_Konstantin_Hintermayer_smarterrent/Dockerfile
|
buildah build -t ${{ github.sha }} ./Einheit_4/2025_5BHITN_Konstantin_Hintermayer_smarterrent/Dockerfile
|
||||||
buildah build -t ${{ github.sha }}-tooling ./Einheit_4/tooling_container/Dockerfile
|
buildah build -t ${{ github.sha }}-tooling -f ./Einheit_4/tooling_container/Dockerfile .
|
||||||
buildah tag ${{ github.sha }} latest
|
buildah tag ${{ github.sha }} latest
|
||||||
|
|
||||||
- name: Push Docker Images
|
- name: Push Docker Images
|
||||||
run: |
|
run: |
|
||||||
buildah push ${{ github.sha }} docker://git.kocoder.xyz/kocoded/2025_5BHITN_Hintermayer_Konstantin_smarterrent_db:${{ github.sha }}
|
buildah push ${{ github.sha }} docker://git.kocoder.xyz/kocoded/kocoder_smarterrent:${{ github.sha }}
|
||||||
buildah push ${{ github.sha }}-tooling docker://git.kocoder.xyz/kocoded/2025_5BHITN_Hintermayer_Konstantin_smarterrent_db_init_db:${{ github.sha }}
|
buildah push ${{ github.sha }}-tooling docker://git.kocoder.xyz/kocoded/kocoder_smarterrent_init_db:${{ github.sha }}
|
||||||
buildah push latest docker://git.kocoder.xyz/kocoded/2025_5BHITN_Hintermayer_Konstantin_smarterrent_db:latest
|
buildah push latest docker://git.kocoder.xyz/kocoded/kocoder_smarterrent:latest
|
||||||
|
|||||||
@@ -1,69 +1,82 @@
|
|||||||
CREATE DATABASE "2025_5bhitn_konstantin_hintermayer_smarter_rentDB";
|
IF NOT EXISTS (SELECT name FROM sys.databases WHERE name = '2025_5bhitn_konstantin_hintermayer_smarter_rentDB')
|
||||||
GO
|
BEGIN
|
||||||
USE "2025_5bhitn_konstantin_hintermayer_smarter_rentDB";
|
CREATE DATABASE [2025_5bhitn_konstantin_hintermayer_smarter_rentDB];
|
||||||
|
END;
|
||||||
GO
|
GO
|
||||||
|
|
||||||
DROP TABLE IF EXISTS Rental;
|
USE [2025_5bhitn_konstantin_hintermayer_smarter_rentDB];
|
||||||
|
GO
|
||||||
|
|
||||||
DROP TABLE IF EXISTS Customer;
|
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Customer]') AND type = 'U')
|
||||||
|
BEGIN
|
||||||
|
CREATE TABLE Customer (
|
||||||
|
id BIGINT NOT NULL IDENTITY (1, 1),
|
||||||
|
[name] VARCHAR(50) NOT NULL,
|
||||||
|
Adress VARCHAR(100) NOT NULL,
|
||||||
|
driverlicenseid VARCHAR(100) NOT NULL,
|
||||||
|
PRIMARY KEY (id)
|
||||||
|
);
|
||||||
|
END;
|
||||||
|
|
||||||
DROP TABLE IF EXISTS [Location];
|
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Location]') AND type = 'U')
|
||||||
|
BEGIN
|
||||||
|
CREATE TABLE Location (
|
||||||
|
id BIGINT NOT NULL IDENTITY (1, 1),
|
||||||
|
[name] VARCHAR(250) NOT NULL,
|
||||||
|
[address] VARCHAR(250) NOT NULL,
|
||||||
|
PRIMARY KEY (id)
|
||||||
|
);
|
||||||
|
END;
|
||||||
|
|
||||||
DROP TABLE IF EXISTS Vehicle;
|
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[VehicleCategory]') AND type = 'U')
|
||||||
|
BEGIN
|
||||||
|
CREATE TABLE VehicleCategory (
|
||||||
|
id BIGINT NOT NULL IDENTITY (1, 1),
|
||||||
|
[description] VARCHAR(250) NOT NULL,
|
||||||
|
pricePerDay DECIMAL NOT NULL,
|
||||||
|
PRIMARY KEY (id)
|
||||||
|
);
|
||||||
|
END;
|
||||||
|
|
||||||
DROP TABLE IF EXISTS VehicleCategory;
|
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Vehicle]') AND type = 'U')
|
||||||
|
BEGIN
|
||||||
|
CREATE TABLE Vehicle (
|
||||||
|
id BIGINT NOT NULL IDENTITY (1, 1),
|
||||||
|
brand VARCHAR(50) NOT NULL,
|
||||||
|
model VARCHAR(50) NOT NULL,
|
||||||
|
licensePlate VARCHAR(8) NOT NULL,
|
||||||
|
buyDate DATE NOT NULL,
|
||||||
|
locationID BIGINT NOT NULL,
|
||||||
|
vehicleCategoryID BIGINT NOT NULL,
|
||||||
|
PRIMARY KEY (id)
|
||||||
|
);
|
||||||
|
|
||||||
CREATE TABLE Customer (
|
ALTER TABLE Vehicle
|
||||||
id BIGINT NOT NULL IDENTITY (1, 1),
|
ADD CONSTRAINT FK_Location_TO_Vehicle FOREIGN KEY (locationID) REFERENCES Location (id);
|
||||||
[name] VARCHAR(50) NOT NULL,
|
|
||||||
Adress VARCHAR(100) NOT NULL,
|
|
||||||
driverlicenseid VARCHAR(100) NOT NULL,
|
|
||||||
PRIMARY KEY (id)
|
|
||||||
);
|
|
||||||
|
|
||||||
CREATE TABLE Location (
|
ALTER TABLE Vehicle
|
||||||
id BIGINT NOT NULL IDENTITY (1, 1),
|
ADD CONSTRAINT FK_VehicleCategory_TO_Vehicle FOREIGN KEY (vehicleCategoryID) REFERENCES VehicleCategory (id);
|
||||||
[name] VARCHAR(250) NOT NULL,
|
END;
|
||||||
[address] VARCHAR(250) NOT NULL,
|
|
||||||
PRIMARY KEY (id)
|
|
||||||
);
|
|
||||||
|
|
||||||
CREATE TABLE Rental (
|
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Rental]') AND type = 'U')
|
||||||
id BIGINT NOT NULL IDENTITY (1, 1),
|
BEGIN
|
||||||
rentalStart DATETIME NOT NULL,
|
CREATE TABLE Rental (
|
||||||
rentalEnd DATETIME NOT NULL,
|
id BIGINT NOT NULL IDENTITY (1, 1),
|
||||||
actualEnd DATETIME NULL,
|
rentalStart DATETIME NOT NULL,
|
||||||
customerID BIGINT NOT NULL,
|
rentalEnd DATETIME NOT NULL,
|
||||||
vehicleID BIGINT NOT NULL,
|
actualEnd DATETIME NULL,
|
||||||
PRIMARY KEY (id)
|
customerID BIGINT NOT NULL,
|
||||||
);
|
vehicleID BIGINT NOT NULL,
|
||||||
|
PRIMARY KEY (id)
|
||||||
|
);
|
||||||
|
|
||||||
CREATE TABLE Vehicle (
|
|
||||||
id BIGINT NOT NULL IDENTITY (1, 1),
|
|
||||||
brand VARCHAR(50) NOT NULL,
|
|
||||||
model VARCHAR(50) NOT NULL,
|
|
||||||
licensePlate VARCHAR(8) NOT NULL,
|
|
||||||
buyDate DATE NOT NULL,
|
|
||||||
locationID BIGINT NOT NULL,
|
|
||||||
vehicleCategoryID BIGINT NOT NULL,
|
|
||||||
PRIMARY KEY (id)
|
|
||||||
);
|
|
||||||
|
|
||||||
CREATE TABLE VehicleCategory (
|
ALTER TABLE Rental
|
||||||
id BIGINT NOT NULL IDENTITY (1, 1),
|
ADD CONSTRAINT FK_Customer_TO_Rental FOREIGN KEY (customerID) REFERENCES Customer (id);
|
||||||
[description] VARCHAR(250) NOT NULL,
|
|
||||||
pricePerDay DECIMAL NOT NULL,
|
|
||||||
PRIMARY KEY (id)
|
|
||||||
);
|
|
||||||
|
|
||||||
ALTER TABLE Rental
|
ALTER TABLE Rental
|
||||||
ADD CONSTRAINT FK_Customer_TO_Rental FOREIGN KEY (customerID) REFERENCES Customer (id);
|
ADD CONSTRAINT FK_Vehicle_TO_Rental FOREIGN KEY (vehicleID) REFERENCES Vehicle (id);
|
||||||
|
END;
|
||||||
|
|
||||||
ALTER TABLE Rental
|
|
||||||
ADD CONSTRAINT FK_Vehicle_TO_Rental FOREIGN KEY (vehicleID) REFERENCES Vehicle (id);
|
|
||||||
|
|
||||||
ALTER TABLE Vehicle
|
|
||||||
ADD CONSTRAINT FK_Location_TO_Vehicle FOREIGN KEY (locationID) REFERENCES Location (id);
|
|
||||||
|
|
||||||
ALTER TABLE Vehicle
|
|
||||||
ADD CONSTRAINT FK_VehicleCategory_TO_Vehicle FOREIGN KEY (vehicleCategoryID) REFERENCES VehicleCategory (id);
|
|
||||||
@@ -1,3 +1,6 @@
|
|||||||
|
USE [2025_5bhitn_konstantin_hintermayer_smarter_rentDB];
|
||||||
|
GO
|
||||||
|
|
||||||
-- Insert test data into the Location table
|
-- Insert test data into the Location table
|
||||||
INSERT INTO [dbo].[Location] ([name], [address])
|
INSERT INTO [dbo].[Location] ([name], [address])
|
||||||
VALUES
|
VALUES
|
||||||
|
|||||||
@@ -1,3 +1,7 @@
|
|||||||
|
USE [2025_5bhitn_konstantin_hintermayer_smarter_rentDB];
|
||||||
|
GO
|
||||||
|
|
||||||
|
|
||||||
-- ####################################################
|
-- ####################################################
|
||||||
-- # STORED PROCEDURES #
|
-- # STORED PROCEDURES #
|
||||||
-- ####################################################
|
-- ####################################################
|
||||||
|
|||||||
2
Einheit_4/2025_5BHITN_Konstantin_Hintermayer_smarterrent/.gitignore
vendored
Normal file
2
Einheit_4/2025_5BHITN_Konstantin_Hintermayer_smarterrent/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
bin/
|
||||||
|
obj/
|
||||||
@@ -1,4 +1,9 @@
|
|||||||
@inherits LayoutComponentBase
|
@using Services
|
||||||
|
@inherits LayoutComponentBase
|
||||||
|
@implements IDisposable
|
||||||
|
@rendermode RenderMode.InteractiveServer
|
||||||
|
@inject IErrorService ErrorService
|
||||||
|
|
||||||
|
|
||||||
<div class="page">
|
<div class="page">
|
||||||
<div class="sidebar">
|
<div class="sidebar">
|
||||||
@@ -7,6 +12,13 @@
|
|||||||
|
|
||||||
<main>
|
<main>
|
||||||
<article class="content px-4">
|
<article class="content px-4">
|
||||||
|
@if(ErrorService.ex != null) {
|
||||||
|
<div class="alert alert-danger m-3" role="alert">
|
||||||
|
@ErrorService.ex.Message
|
||||||
|
<button type="button" class="btn-close float-end" aria-label="Close" @onclick="DismissError"></button>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
|
||||||
@Body
|
@Body
|
||||||
</article>
|
</article>
|
||||||
</main>
|
</main>
|
||||||
@@ -17,3 +29,20 @@
|
|||||||
<a href="." class="reload">Reload</a>
|
<a href="." class="reload">Reload</a>
|
||||||
<span class="dismiss">🗙</span>
|
<span class="dismiss">🗙</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@code {
|
||||||
|
protected override void OnInitialized()
|
||||||
|
{
|
||||||
|
ErrorService.OnChange += StateHasChanged;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DismissError()
|
||||||
|
{
|
||||||
|
ErrorService.ex = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
ErrorService.OnChange -= StateHasChanged;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
@page "/ErrorTest"
|
||||||
|
@using Microsoft.Data.SqlClient
|
||||||
|
@using Services
|
||||||
|
@inject IErrorService ErrorService
|
||||||
|
|
||||||
|
<PageTitle>Error Test</PageTitle>
|
||||||
|
|
||||||
|
<h1>Error Page</h1>
|
||||||
|
|
||||||
|
<button @onclick="SetError" class="btn btn-primary">Set Error</button>
|
||||||
|
|
||||||
|
@code {
|
||||||
|
|
||||||
|
private void SetError() {
|
||||||
|
ErrorService.ex = new Exception("Hello World");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,7 +1,9 @@
|
|||||||
@page "/"
|
@page "/"
|
||||||
@using Models
|
@using Models
|
||||||
@using Services
|
@using Services
|
||||||
|
@using System.Runtime.InteropServices
|
||||||
@inject IRentService RentService
|
@inject IRentService RentService
|
||||||
|
@inject IErrorService ErrorService
|
||||||
|
|
||||||
<PageTitle>Home</PageTitle>
|
<PageTitle>Home</PageTitle>
|
||||||
|
|
||||||
@@ -45,9 +47,11 @@
|
|||||||
|
|
||||||
protected override void OnInitialized()
|
protected override void OnInitialized()
|
||||||
{
|
{
|
||||||
_vehicles = RentService.GetAvailableCars();
|
try {
|
||||||
Console.WriteLine("VC" + _vehicles.Count);
|
_vehicles = RentService.GetAvailableCars();
|
||||||
@* return Task.CompletedTask; *@
|
} catch (Exception e) {
|
||||||
|
ErrorService.ex = e;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,33 +1,48 @@
|
|||||||
@page "/rent"
|
@page "/rent"
|
||||||
@using Models
|
@using Models
|
||||||
@using Services
|
@using Services
|
||||||
|
@using System.Runtime.InteropServices
|
||||||
@inject IRentService RentService
|
@inject IRentService RentService
|
||||||
@inject NavigationManager NavigationManager
|
@inject NavigationManager NavigationManager
|
||||||
|
@inject IErrorService ErrorService
|
||||||
|
|
||||||
<PageTitle>Rent</PageTitle>
|
<PageTitle>Rent</PageTitle>
|
||||||
|
|
||||||
<h1>Rent</h1>
|
<h1>Rent</h1>
|
||||||
|
|
||||||
<form @onsubmit="RentCar">
|
<form @onsubmit="RentCar">
|
||||||
<InputSelect @bind-Value="_vehicleId">
|
|
||||||
@foreach (Vehicle v in _vehicles)
|
|
||||||
{
|
|
||||||
<option value=@v.Id>@v.Id - @v.Brand - @v.Model</option>
|
|
||||||
}
|
|
||||||
</InputSelect>
|
|
||||||
|
|
||||||
<InputSelect @bind-Value="_customerId">
|
<div class="form-group mb-3">
|
||||||
@foreach (Customer c in _customers)
|
<label for="vehicle">Vehicle: </label>
|
||||||
{
|
<InputSelect @bind-Value="_vehicleId" id="vehicle" class="form-control" placeholder="Fahrzeug">
|
||||||
<option value=@c.Id>@c.Name</option>
|
@foreach (Vehicle v in _vehicles)
|
||||||
}
|
{
|
||||||
</InputSelect>
|
<option value=@v.Id>@v.Id - @v.Brand - @v.Model</option>
|
||||||
|
}
|
||||||
|
</InputSelect>
|
||||||
|
</div>
|
||||||
|
|
||||||
<InputDate @bind-Value="_from"/>
|
<div class="form-group mb-3">
|
||||||
|
<label for="customer">Kunde: </label>
|
||||||
|
<InputSelect @bind-Value="_customerId" id="customer" class="form-control" placeholder="Kunde">
|
||||||
|
@foreach (Customer c in _customers)
|
||||||
|
{
|
||||||
|
<option value=@c.Id>@c.Name</option>
|
||||||
|
}
|
||||||
|
</InputSelect>
|
||||||
|
</div>
|
||||||
|
|
||||||
<InputDate @bind-Value="_thru"/>
|
<div class="form-group mb-3">
|
||||||
|
<label for="from">Von: </label>
|
||||||
|
<InputDate @bind-Value="_from" class="form-control" id="from" />
|
||||||
|
</div>
|
||||||
|
|
||||||
<button type="submit">Submit</button>
|
<div class="form-group mb-3">
|
||||||
|
<label for="thru">Bis: </label>
|
||||||
|
<InputDate @bind-Value="_thru" class="form-control" id="thru" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<button type="submit" class="btn btn-primary">Mieten!</button>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
@code {
|
@code {
|
||||||
@@ -41,15 +56,22 @@
|
|||||||
|
|
||||||
protected override void OnInitialized()
|
protected override void OnInitialized()
|
||||||
{
|
{
|
||||||
_vehicles = RentService.GetAvailableCars();
|
try {
|
||||||
_customers = RentService.GetCustomers();
|
_vehicles = RentService.GetAvailableCars();
|
||||||
|
_customers = RentService.GetCustomers();
|
||||||
|
} catch (Exception e) {
|
||||||
|
ErrorService.ex = e;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Task RentCar()
|
private Task RentCar()
|
||||||
{
|
{
|
||||||
RentService.RentCar(_customerId, _vehicleId, _from, _thru);
|
try {
|
||||||
Console.WriteLine("Rented Car");
|
RentService.RentCar(_customerId, _vehicleId, _from, _thru);
|
||||||
NavigationManager.NavigateTo("/");
|
NavigationManager.NavigateTo("/");
|
||||||
|
} catch (Exception e) {
|
||||||
|
ErrorService.ex = e;
|
||||||
|
}
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
@using Models
|
@using Models
|
||||||
@using Services
|
@using Services
|
||||||
@inject IRollbackService RollbackService
|
@inject IRollbackService RollbackService
|
||||||
|
@inject IErrorService ErrorService
|
||||||
|
|
||||||
<PageTitle>Rollback</PageTitle>
|
<PageTitle>Rollback</PageTitle>
|
||||||
|
|
||||||
@@ -12,7 +13,11 @@
|
|||||||
|
|
||||||
@code {
|
@code {
|
||||||
private Task PerformRollback() {
|
private Task PerformRollback() {
|
||||||
RollbackService.ResetToDefaults();
|
try {
|
||||||
|
RollbackService.ResetToDefaults();
|
||||||
|
} catch (Exception e) {
|
||||||
|
ErrorService.ex = e;
|
||||||
|
}
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ public static class ServiceCollectionExtension
|
|||||||
|
|
||||||
services.Services.AddScoped<IRentService, RentService>();
|
services.Services.AddScoped<IRentService, RentService>();
|
||||||
services.Services.AddScoped<IRollbackService, RollbackService>();
|
services.Services.AddScoped<IRollbackService, RollbackService>();
|
||||||
|
services.Services.AddScoped<IErrorService, ErrorService>();
|
||||||
return services;
|
return services;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
SELECT * FROM Vehicle;
|
|
||||||
SELECT * FROM Rental;
|
|
||||||
SELECT * FROM v_VerfuegbareFahrzeuge;
|
|
||||||
|
|
||||||
-- Create Snapshot;
|
|
||||||
CREATE DATABASE [2025_5bhitn_konstantin_hintermayer_smarter_rentDB_snapshot]
|
|
||||||
ON
|
|
||||||
(
|
|
||||||
NAME = [2025_5bhitn_konstantin_hintermayer_smarter_rentDB],
|
|
||||||
FILENAME = N'/var/opt/mssql/data/smarter_rentDB.ss'
|
|
||||||
) AS SNAPSHOT OF [2025_5bhitn_konstantin_hintermayer_smarter_rentDB];
|
|
||||||
GO
|
|
||||||
|
|
||||||
-- Restore Snapshot
|
|
||||||
|
|
||||||
USE [master];
|
|
||||||
ALTER DATABASE [2025_5bhitn_konstantin_hintermayer_smarter_rentDB] SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
|
|
||||||
RESTORE DATABASE [2025_5bhitn_konstantin_hintermayer_smarter_rentDB] FROM DATABASE_SNAPSHOT = '2025_5bhitn_konstantin_hintermayer_smarter_rentDB_snapshot';
|
|
||||||
GO
|
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
using System.Data;
|
||||||
|
using Configuration;
|
||||||
|
using Microsoft.Data.SqlClient;
|
||||||
|
using Models;
|
||||||
|
|
||||||
|
namespace Services
|
||||||
|
{
|
||||||
|
public interface IErrorService
|
||||||
|
{
|
||||||
|
Exception? ex { get; set; }
|
||||||
|
event Action? OnChange;
|
||||||
|
}
|
||||||
|
|
||||||
|
public class ErrorService : IErrorService
|
||||||
|
{
|
||||||
|
private Exception? _ex;
|
||||||
|
public Exception? ex
|
||||||
|
{
|
||||||
|
get => _ex;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_ex = value;
|
||||||
|
NotifyStateChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public event Action? OnChange;
|
||||||
|
private void NotifyStateChanged() => OnChange?.Invoke();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -17,22 +17,16 @@ namespace Services
|
|||||||
public List<Vehicle> GetAvailableCars()
|
public List<Vehicle> GetAvailableCars()
|
||||||
{
|
{
|
||||||
List<Vehicle> vehicles = new List<Vehicle>();
|
List<Vehicle> vehicles = new List<Vehicle>();
|
||||||
try
|
|
||||||
{
|
|
||||||
using SqlConnection conn = sqlConnectionFactory.CreateSqlConnection();
|
|
||||||
string sql = "SELECT * FROM v_VerfuegbareFahrzeuge;";
|
|
||||||
SqlCommand cmd = new SqlCommand(sql, conn);
|
|
||||||
|
|
||||||
using SqlDataReader reader = cmd.ExecuteReader();
|
using SqlConnection conn = sqlConnectionFactory.CreateSqlConnection();
|
||||||
|
string sql = "SELECT * FROM v_VerfuegbareFahrzeuge;";
|
||||||
|
SqlCommand cmd = new SqlCommand(sql, conn);
|
||||||
|
|
||||||
while (reader.Read())
|
using SqlDataReader reader = cmd.ExecuteReader();
|
||||||
{
|
|
||||||
vehicles.Add(Vehicle.FromReader(reader));
|
while (reader.Read())
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
{
|
||||||
Console.WriteLine(e);
|
vehicles.Add(Vehicle.FromReader(reader));
|
||||||
}
|
}
|
||||||
|
|
||||||
return vehicles;
|
return vehicles;
|
||||||
@@ -41,45 +35,34 @@ namespace Services
|
|||||||
public List<Customer> GetCustomers()
|
public List<Customer> GetCustomers()
|
||||||
{
|
{
|
||||||
List<Customer> customers = new List<Customer>();
|
List<Customer> customers = new List<Customer>();
|
||||||
try
|
|
||||||
|
using SqlConnection conn = sqlConnectionFactory.CreateSqlConnection();
|
||||||
|
string sql = "SELECT * FROM Customer;";
|
||||||
|
SqlCommand cmd = new SqlCommand(sql, conn);
|
||||||
|
|
||||||
|
using SqlDataReader reader = cmd.ExecuteReader();
|
||||||
|
|
||||||
|
while (reader.Read())
|
||||||
{
|
{
|
||||||
using SqlConnection conn = sqlConnectionFactory.CreateSqlConnection();
|
customers.Add(Customer.FromReader(reader));
|
||||||
string sql = "SELECT * FROM Customer;";
|
|
||||||
SqlCommand cmd = new SqlCommand(sql, conn);
|
|
||||||
|
|
||||||
using SqlDataReader reader = cmd.ExecuteReader();
|
|
||||||
|
|
||||||
while (reader.Read())
|
|
||||||
{
|
|
||||||
customers.Add(Customer.FromReader(reader));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
Console.WriteLine(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
return customers;
|
return customers;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RentCar(long customerId, long vehicleId, DateTime start, DateTime end)
|
public void RentCar(long customerId, long vehicleId, DateTime start, DateTime end)
|
||||||
{
|
{
|
||||||
try
|
|
||||||
{
|
using SqlConnection conn = sqlConnectionFactory.CreateSqlConnection();
|
||||||
using SqlConnection conn = sqlConnectionFactory.CreateSqlConnection();
|
using SqlCommand cmd = new SqlCommand("sp_MieteFahrzeug", conn);
|
||||||
using SqlCommand cmd = new SqlCommand("sp_MieteFahrzeug", conn);
|
cmd.CommandType = CommandType.StoredProcedure;
|
||||||
cmd.CommandType = CommandType.StoredProcedure;
|
|
||||||
|
|
||||||
cmd.Parameters.AddWithValue("@KundeID", customerId);
|
cmd.Parameters.AddWithValue("@KundeID", customerId);
|
||||||
cmd.Parameters.AddWithValue("@FahrzeugID", vehicleId);
|
cmd.Parameters.AddWithValue("@FahrzeugID", vehicleId);
|
||||||
cmd.Parameters.AddWithValue("@Start", start);
|
cmd.Parameters.AddWithValue("@Start", start);
|
||||||
cmd.Parameters.AddWithValue("@Ende", end);
|
cmd.Parameters.AddWithValue("@Ende", end);
|
||||||
|
|
||||||
cmd.ExecuteNonQuery();
|
cmd.ExecuteNonQuery();
|
||||||
}catch (Exception ex)
|
|
||||||
{
|
|
||||||
Console.WriteLine(ex);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -14,24 +14,17 @@ namespace Services
|
|||||||
{
|
{
|
||||||
public void ResetToDefaults()
|
public void ResetToDefaults()
|
||||||
{
|
{
|
||||||
try
|
using SqlConnection conn = sqlConnectionFactory.CreateSqlConnection();
|
||||||
{
|
|
||||||
using SqlConnection conn = sqlConnectionFactory.CreateSqlConnection();
|
|
||||||
|
|
||||||
string sql = @"
|
string sql = @"
|
||||||
USE [master];
|
USE [master];
|
||||||
ALTER DATABASE [2025_5bhitn_konstantin_hintermayer_smarter_rentDB] SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
|
ALTER DATABASE [2025_5bhitn_konstantin_hintermayer_smarter_rentDB] SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
|
||||||
RESTORE DATABASE [2025_5bhitn_konstantin_hintermayer_smarter_rentDB] FROM DATABASE_SNAPSHOT = '2025_5bhitn_konstantin_hintermayer_smarter_rentDB_snapshot';
|
RESTORE DATABASE [2025_5bhitn_konstantin_hintermayer_smarter_rentDB] FROM DATABASE_SNAPSHOT = '2025_5bhitn_konstantin_hintermayer_smarter_rentDB_snapshot';
|
||||||
ALTER DATABASE [2025_5bhitn_konstantin_hintermayer_smarter_rentDB] SET MULTI_USER;";
|
ALTER DATABASE [2025_5bhitn_konstantin_hintermayer_smarter_rentDB] SET MULTI_USER;";
|
||||||
|
|
||||||
using SqlCommand cmd = new SqlCommand(sql, conn);
|
using SqlCommand cmd = new SqlCommand(sql, conn);
|
||||||
|
|
||||||
cmd.ExecuteNonQuery();
|
cmd.ExecuteNonQuery();
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Console.WriteLine(ex);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,8 +2,11 @@ FROM mcr.microsoft.com/mssql-tools
|
|||||||
WORKDIR /App
|
WORKDIR /App
|
||||||
|
|
||||||
# Copy everything
|
# Copy everything
|
||||||
COPY ../../Einheit_1/2025_5BHITN_Konstantin_Hintermayer_create_schema.sql ./01.sql
|
COPY ./Einheit_1/2025_5BHITN_Konstantin_Hintermayer_create_schema.sql ./01.sql
|
||||||
COPY ../../Einheit_2/2025_5BHITN_Konstantin_Hintermayer_seed_database.sql ./02.sql
|
COPY ./Einheit_2/2025_5BHITN_Konstantin_Hintermayer_seed_database.sql ./02.sql
|
||||||
COPY ../../Einheit_3/2025_5BHITN_Konstantin_Hintermayer_procedures_and_triggers.sql ./03.sql
|
COPY ./Einheit_3/2025_5BHITN_Konstantin_Hintermayer_procedures_and_triggers.sql ./03.sql
|
||||||
|
COPY ./Einheit_5/2025_5BHITN_Konstantin_Hintermayer_snapshot_from_database.sql ./04.sql
|
||||||
|
|
||||||
ENTRYPOINT ["sqlcmd", "-D", ""]
|
COPY ./Einheit_4/tooling_container/entrypoint.sh .
|
||||||
|
|
||||||
|
ENTRYPOINT ["./entrypoint.sh"]
|
||||||
@@ -1,16 +1,15 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# Wait for SQL Server to boot up (adjust sleep if needed)
|
|
||||||
echo "Waiting for SQL Server to start..."
|
|
||||||
sleep 20s
|
|
||||||
|
|
||||||
# Run the three SQL files using sqlcmd
|
# Run the three SQL files using sqlcmd
|
||||||
# -S: Server, -U: User, -P: Password (passed via ENV)
|
# -S: Server, -U: User, -P: Password (passed via ENV)
|
||||||
|
sleep 20
|
||||||
|
|
||||||
|
|
||||||
echo "Applying SQL files..."
|
echo "Applying SQL files..."
|
||||||
|
|
||||||
for migration in $(ls . | grep -E '\.sql$')
|
for migration in $(ls . | grep -E '\.sql$')
|
||||||
do
|
do
|
||||||
echo "Applying $migration."
|
echo "Applying $migration."
|
||||||
/opt/mssql-tools/bin/sqlcmd -D $DSN_PASSWORD -i $migration.sql
|
/opt/mssql-tools/bin/sqlcmd -S mssql-service -U sa -C -P "$DSN_PASSWORD" -i $migration
|
||||||
done
|
done
|
||||||
|
|
||||||
echo "Database initialization complete."
|
echo "Database initialization complete."
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
CREATE DATABASE [2025_5bhitn_konstantin_hintermayer_smarter_rentDB_snapshot]
|
||||||
|
ON
|
||||||
|
(
|
||||||
|
NAME = [2025_5bhitn_konstantin_hintermayer_smarter_rentDB],
|
||||||
|
FILENAME = N'/var/opt/mssql/data/smarter_rentDB.ss'
|
||||||
|
) AS SNAPSHOT OF [2025_5bhitn_konstantin_hintermayer_smarter_rentDB];
|
||||||
|
GO
|
||||||
Reference in New Issue
Block a user