Projektdateien hinzufügen.

This commit is contained in:
BuildTools committed 2024-01-15 19:02:47 +01:00
1 parent c0cb99b0e9
commit 45b33fcc3a
71 files changed
+17840

No files matched your search

+100
View File
@@ -0,0 +1,100 @@
@using Microsoft.EntityFrameworkCore
@using CocktailWeb.Data
@page "/cocktails/add"
@inject IDbContextFactory<DbDataContext> DataContextFactory;
@inject NavigationManager nav;
@inject IWebHostEnvironment env;
<h3>Cocktail hinzufügen</h3>
<div class="d-flex gap-3">
<div class="border border-2 rounded p-3 w-100">
<h4>Mein Cocktail</h4>
<div class="mb-3">
<label class="form-label" for="cocktailname">Cocktailname</label>
<input id="cocktailname" name="cocktailname" type="text" class="form-control" @bind="@EditCocktail.Name" />
</div>
<div class="mb-3">
<label class="form-label" for="cocktailimage">Bild</label>
<InputFile OnChange="Bild_OnChange" class="form-control" id="cocktailimage" name="cocktailimage" accept=".jpg,.png,.jpeg,.gif,.webp" />
</div>
<h5>Cocktail-Zutaten</h5>
<table class="table align-middle">
<tbody>
@if (EditCocktail.Cocktailflaschen.Count == 0)
{
<tr>
<td class="disabled" aria-disabled="true">Noch keine Zutaten hinzugefügt</td>
</tr>
}
else
{
@foreach (CocktailFlasche cf in EditCocktail.Cocktailflaschen.OrderBy(cf => cf.Reihenfolge))
{
<tr>
<th>@cf.Reihenfolge</th>
<th>@cf.Flasche.Name</th>
<td>
<div class="input-group">
<input class="form-control" id="Menge" name="menge" type="text" @bind="@cf.Menge" />
<span class="input-group-text">ml</span>
</div>
</td>
<td>
<div class="btn-group">
<button class="btn btn-outline-secondary" @onclick="args => FlascheReihenfolge(args, cf,-2)">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-caret-up-fill" viewBox="0 0 16 16">
<path d="m7.247 4.86-4.796 5.481c-.566.647-.106 1.659.753 1.659h9.592a1 1 0 0 0 .753-1.659l-4.796-5.48a1 1 0 0 0-1.506 0z" />
</svg>
</button>
<button class="btn btn-outline-secondary" @onclick="args => FlascheReihenfolge(args, cf ,2)">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-caret-down-fill" viewBox="0 0 16 16">
<path d="M7.247 11.14 2.451 5.658C1.885 5.013 2.345 4 3.204 4h9.592a1 1 0 0 1 .753 1.659l-4.796 5.48a1 1 0 0 1-1.506 0z" />
</svg>
</button>
</div>
</td>
<td>
<button class="btn btn-outline-danger" @onclick="args => FlascheEntfernen(args, cf)">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-dash-circle" viewBox="0 0 16 16">
<path d="M8 15A7 7 0 1 1 8 1a7 7 0 0 1 0 14m0 1A8 8 0 1 0 8 0a8 8 0 0 0 0 16" />
<path d="M4 8a.5.5 0 0 1 .5-.5h7a.5.5 0 0 1 0 1h-7A.5.5 0 0 1 4 8" />
</svg>
</button>
</td>
</tr>
}
}
</tbody>
</table>
<button @onclick="OnSubmit" class="btn btn-primary">Speichern</button>
<button @onclick="@(() => nav.NavigateTo("/cocktails"))" class="btn btn-secondary">Abbrechen</button>
</div>
<div class="border border-2 rounded p-3 w-100">
<h4>Verfügbare Zutaten</h4>
<ul class="list-group">
@if (FlaschenListe.Count == 0)
{
<li class="list-group-item list-group-item-action align-middle">
Es wurden noch keine Zutaten angelegt
</li>
}
else
{
@foreach (Flasche fl in FlaschenListe)
{
<li class="list-group-item list-group-item-action align-middle" @onclick="args => FlascheHinzufuegen(args,fl)">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-plus-circle text-success" viewBox="0 0 16 16">
<path d="M8 15A7 7 0 1 1 8 1a7 7 0 0 1 0 14m0 1A8 8 0 1 0 8 0a8 8 0 0 0 0 16" />
<path d="M8 4a.5.5 0 0 1 .5.5v3h3a.5.5 0 0 1 0 1h-3v3a.5.5 0 0 1-1 0v-3h-3a.5.5 0 0 1 0-1h3v-3A.5.5 0 0 1 8 4" />
</svg>
<label class="form-check-label stretched-link">@fl.Name</label>
</li>
}
}
</ul>
</div>
</div>
@@ -0,0 +1,112 @@
using CocktailWeb;
using CocktailWeb.Data;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Forms;
using Microsoft.AspNetCore.Components.Web;
using Microsoft.EntityFrameworkCore;
namespace CocktailWeb.Pages
{
public partial class CocktailHinzufuegen
{
public List<Flasche> FlaschenListe { get; set; } = new();
public Cocktail EditCocktail = new();
private IBrowserFile? CocktaiLBildDatei;
private DbDataContext? _DataContext;
private int MaxAllowedUploadSizeInMB = 10;
private string ImageUploadDir = "cocktails";
protected override async Task OnInitializedAsync()
{
await FillFlaschenListe();
}
public async Task FillFlaschenListe()
{
_DataContext ??= await DataContextFactory.CreateDbContextAsync();
if (_DataContext != null)
{
FlaschenListe = await _DataContext.Flaschen.OrderBy(f => f.Name).ToListAsync();
}
}
public void FlascheHinzufuegen(MouseEventArgs e, Flasche f)
{
EditCocktail.Cocktailflaschen.Add(new CocktailFlasche() { Flasche = f, Reihenfolge = EditCocktail.Cocktailflaschen.Count + 1 });
CocktailFlaschenSortieren();
}
public void FlascheEntfernen(MouseEventArgs e, CocktailFlasche cf)
{
EditCocktail.Cocktailflaschen.Remove(cf);
CocktailFlaschenSortieren();
}
/// <summary>
/// Geht die Liste durch und setzt die Reihenfolge neu
/// </summary>
void CocktailFlaschenSortieren()
{
// Reihenfolge neu sortieren, damit keine Lücken entstehen
int i = 1;
foreach (var c in EditCocktail.Cocktailflaschen.OrderBy(cf => cf.Reihenfolge))
{
c.Reihenfolge = i;
i++;
}
}
public void FlascheReihenfolge(MouseEventArgs e, CocktailFlasche cf, int Richtung)
{
cf.Reihenfolge += Richtung;
CocktailFlaschenSortieren();
}
public void Bild_OnChange(InputFileChangeEventArgs e)
{
CocktaiLBildDatei = e.GetMultipleFiles().FirstOrDefault();
//this.StateHasChanged(); War in nem Stackexchange.. Nötig?
}
private async Task OnSubmit(EventArgs e)
{
_DataContext ??= await DataContextFactory.CreateDbContextAsync();
if (EditCocktail != null && _DataContext != null)
{
_DataContext.Cocktails.Add(EditCocktail);
await _DataContext.SaveChangesAsync();
if (CocktaiLBildDatei != null)
{
try
{
// Bild hochladen
var relativeuploadpath = Path.Join(ImageUploadDir, $"{EditCocktail.Id}{Path.GetExtension(CocktaiLBildDatei.Name)}");
var fullpath = Path.Join(env.WebRootPath, relativeuploadpath);
string? folder = Path.GetDirectoryName(fullpath);
if (folder != null && !Path.Exists(folder)) Directory.CreateDirectory(folder);
Stream stream = CocktaiLBildDatei.OpenReadStream(maxAllowedSize: MaxAllowedUploadSizeInMB * 1024 * 1024);
FileStream fs = File.Create(fullpath);
await stream.CopyToAsync(fs);
stream.Close();
fs.Close();
EditCocktail.ImageURL = relativeuploadpath;
// URL hinterlegen und wieder speichern
_DataContext.Cocktails.Update(EditCocktail);
await _DataContext.SaveChangesAsync();
}
catch (Exception ex)
{
Console.WriteLine($"Error uploading image: {ex.Message}");
}
}
}
nav.NavigateTo("/cocktails");
}
}
}
+34
View File
@@ -0,0 +1,34 @@
@page "/cocktails/{CocktailId}"
@using CocktailWeb.Data
@using Microsoft.EntityFrameworkCore
@inject IDbContextFactory<DbDataContext> DataContextFactory;
@if(SelectedCocktail != null)
{
<h3>@SelectedCocktail.Name</h3>
} else
{
<h3>Cocktail konnte nicht gefunden werden</h3>
}
@code {
[Parameter]
public string? CocktailId { get; set; }
private DbDataContext? _DataContext;
private Cocktail? SelectedCocktail;
protected override async Task OnInitializedAsync()
{
int id = Convert.ToInt32(CocktailId);
_DataContext ??= await DataContextFactory.CreateDbContextAsync();
if (_DataContext != null)
{
SelectedCocktail = _DataContext.Cocktails.FirstOrDefault(c => c.Id == id);
}
}
}
+37
View File
@@ -0,0 +1,37 @@
@page "/cocktails"
@using CocktailWeb.Data
@using Microsoft.EntityFrameworkCore
@inject IDbContextFactory<DbDataContext> DataContextFactory;
@inject IWebHostEnvironment env;
<!--<h3>Cocktails</h3>-->
<a href="/cocktails/add">Cocktail hinzufügen</a>
<div class="container py-2 border border-5 overflow-auto d-inline-block">
<div class="row flex-nowrap">
@foreach (Cocktail c in CocktailListe)
{
<div class="col">
<a href="/cocktails/@c.Id">
<div class="card" style="width: 18rem;">
@if (c.ImageURL != null && File.Exists(Path.Join(env.WebRootPath, c.ImageURL)))
{
<img class="card-img-top" src="@($"/{c.ImageURL}")" alt="@c.Name">
}
else
{
<img class="card-img-top" src="@($"/img/cocktail-default.jpg")" alt="@c.Name">
}
<div class="card-body">
<h5 class="card-title">@c.Name</h5>
<!--<p class="card-text">
Testy
</p>-->
</div>
</div>
</a>
</div>
}
</div>
</div>
+30
View File
@@ -0,0 +1,30 @@
using CocktailWeb;
using CocktailWeb.Data;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Forms;
using Microsoft.AspNetCore.Components.Web;
using Microsoft.EntityFrameworkCore;
namespace CocktailWeb.Pages
{
public partial class Cocktails
{
private DbDataContext? _DataContext;
private List<Cocktail> CocktailListe { get; set; } = new();
protected override async Task OnInitializedAsync()
{
await ShowCocktails();
}
private async Task ShowCocktails()
{
_DataContext ??= await DataContextFactory.CreateDbContextAsync();
if (_DataContext != null)
{
CocktailListe = await _DataContext.Cocktails.OrderBy(f => f.Name).ToListAsync();
}
}
}
}
+43
View File
@@ -0,0 +1,43 @@
@page
@using CocktailWeb.Pages
@model ErrorModel
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<title>Error</title>
<link href="~/css/bootstrap/bootstrap.min.css" rel="stylesheet" />
<link href="~/css/site.css" rel="stylesheet" asp-append-version="true" />
</head>
<body>
<div class="main">
<div class="content px-4">
<h1 class="text-danger">Error.</h1>
<h2 class="text-danger">An error occurred while processing your request.</h2>
@if (Model.ShowRequestId)
{
<p>
<strong>Request ID:</strong> <code>@Model.RequestId</code>
</p>
}
<h3>Development Mode</h3>
<p>
Swapping to the <strong>Development</strong> environment displays detailed information about the error that occurred.
</p>
<p>
<strong>The Development environment shouldn't be enabled for deployed applications.</strong>
It can result in displaying sensitive information from exceptions to end users.
For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>
and restarting the app.
</p>
</div>
</div>
</body>
</html>
+27
View File
@@ -0,0 +1,27 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using System.Diagnostics;
namespace CocktailWeb.Pages
{
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
[IgnoreAntiforgeryToken]
public class ErrorModel : PageModel
{
public string? RequestId { get; set; }
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
private readonly ILogger<ErrorModel> _logger;
public ErrorModel(ILogger<ErrorModel> logger)
{
_logger = logger;
}
public void OnGet()
{
RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
}
}
}
+75
View File
@@ -0,0 +1,75 @@
@using Microsoft.EntityFrameworkCore
@using CocktailWeb.Data
@page "/flaschen"
@inject IDbContextFactory<DbDataContext> FlascheDataContextFactory;
<PageTitle>Flaschen</PageTitle>
@if (CreateFormVisible && FlascheToCreate != null)
{
<h3>Flasche hinzufügen</h3>
<div class="row">
<label for="Name" class="col-4 col-form-label">Name</label>
<div class="col-8">
<input id="Name" name="Name" type="text" class="form-control" @bind="@FlascheToCreate.Name" />
</div>
</div>
<div class="form-group row">
<div class="offset-4 col-8">
<button name="submit" type="submit" class="btn btn-primary" @onclick="CreateNewFlasche">Submit</button>
</div>
</div>
}
else
{
<div class="form-group row">
<div class="offset-4 col-8">
<button name="submit" type="submit" class="btn btn-primary" @onclick="ShowCreateForm">Flasche hinzufügen</button>
</div>
</div>
}
<h3>Flaschen</h3>
@if (FlaschenListe != null && FlaschenListe.Count > 0)
{
<div class="table-responsive">
<table class="table table-striped table-hover table-bordered table-light border-dark">
<thead>
<tr>
<th scope="col">ID</th>
<th scope="col">Name</th>
<th scope="col">Action</th>
</tr>
</thead>
<tbody>
@foreach (var flasche in FlaschenListe)
{
@if (EditFormVisible && FlascheToUpdate != null && FlascheToUpdate.Id == flasche.Id)
{
<tr>
<th scope="row">@FlascheToUpdate.Id</th>
<td> <input id="Name" name="Name" type="text" class="form-control" @bind="@FlascheToUpdate.Name" /></td>
<td><button name="submit" type="submit" class="btn btn-primary" @onclick="() => UpdateEmployee(FlascheToUpdate)">Save</button></td>
</tr>
}
else
{
<tr>
<th scope="row">@flasche.Id</th>
<td>@flasche.Name</td>
<td>
<button name="submit" type="submit" class="btn btn-primary" @onclick="() => ShowEditForm(flasche)">Edit</button>
<button name="submit" type="submit" class="btn btn-primary" @onclick="() => DeleteFlasche(flasche)">Delete</button>
</td>
</tr>
}
}
</tbody>
</table>
</div>
}
@code {
}
+84
View File
@@ -0,0 +1,84 @@
using SQLitePCL;
using Microsoft.EntityFrameworkCore;
using CocktailWeb.Data;
namespace CocktailWeb.Pages
{
public partial class Flaschen
{
public bool CreateFormVisible { get; set; }
public bool EditFormVisible { get; set; }
public Flasche? FlascheToCreate { get; set; }
public Flasche? FlascheToUpdate { get; set; }
public List<Flasche>? FlaschenListe { get; set; }
private DbDataContext? _DataContext;
protected override async Task OnInitializedAsync()
{
CreateFormVisible = false;
await ShowFlaschen();
}
public void ShowCreateForm()
{
FlascheToCreate = new Flasche();
CreateFormVisible = true;
}
public async Task CreateNewFlasche()
{
_DataContext ??= await FlascheDataContextFactory.CreateDbContextAsync();
if (FlascheToCreate != null && _DataContext != null)
{
_DataContext.Flaschen.Add(FlascheToCreate);
await _DataContext.SaveChangesAsync();
}
CreateFormVisible = false;
await ShowFlaschen();
}
public async Task ShowFlaschen()
{
_DataContext ??= await FlascheDataContextFactory.CreateDbContextAsync();
if (_DataContext != null)
{
FlaschenListe = await _DataContext.Flaschen.OrderBy(f => f.Name).ToListAsync();
}
}
public async Task ShowEditForm(Flasche flasche)
{
_DataContext ??= await FlascheDataContextFactory.CreateDbContextAsync();
FlascheToUpdate = _DataContext.Flaschen.FirstOrDefault(f => f.Id == flasche.Id);
EditFormVisible = true;
}
public async Task UpdateEmployee(Flasche flasche)
{
_DataContext ??= await FlascheDataContextFactory.CreateDbContextAsync();
if (_DataContext != null && flasche != null)
{
_DataContext.Flaschen.Update(flasche);
await _DataContext.SaveChangesAsync();
}
EditFormVisible = false;
}
public async Task DeleteFlasche(Flasche flasche)
{
_DataContext ??= await FlascheDataContextFactory.CreateDbContextAsync();
if (_DataContext != null && flasche != null)
{
_DataContext.Flaschen.Remove(flasche);
await _DataContext.SaveChangesAsync();
}
await ShowFlaschen();
}
}
}
+9
View File
@@ -0,0 +1,9 @@
@page "/"
<PageTitle>Index</PageTitle>
<h1>Hello, world!</h1>
Welcome to your new app.
<SurveyPrompt Title="How is Blazor working for you?" />
+37
View File
@@ -0,0 +1,37 @@
@page "/"
@using Microsoft.AspNetCore.Components.Web
@namespace CocktailWeb.Pages
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<base href="~/" />
<link rel="stylesheet" href="css/bootstrap/bootstrap.min.css" />
<link href="css/site.css" rel="stylesheet" />
<link href="CocktailWeb.styles.css" rel="stylesheet" />
<link rel="icon" type="image/png" href="favicon.png"/>
<component type="typeof(HeadOutlet)" render-mode="ServerPrerendered" />
</head>
<body>
<component type="typeof(App)" render-mode="ServerPrerendered" />
<div id="blazor-error-ui">
<environment include="Staging,Production">
An error has occurred. This application may no longer respond until reloaded.
</environment>
<environment include="Development">
An unhandled exception has occurred. See browser dev tools for details.
</environment>
<a href="" class="reload">Reload</a>
<a class="dismiss">🗙</a>
</div>
<script src="_framework/blazor.server.js"></script>
<script src="js/bootstrap.bundle.min.js"></script>
</body>
</html>