Merge pull request #20 from yummy4friends/YUM04-56-datenbankserver-einrichten

WebAPI for database integrity added
This commit is contained in:
FUH22860 2023-06-05 16:48:50 +02:00 committed by GitHub
commit aeac1a81f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
91 changed files with 1556 additions and 50 deletions

View File

@ -0,0 +1,140 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using WebApi.Models;
using WebApi.Data;
namespace WebApi.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class AllergienController : ControllerBase
{
private readonly WebApiContext _context;
public AllergienController(WebApiContext context)
{
_context = context;
}
// GET: api/Allergien
[HttpGet]
public async Task<ActionResult<IEnumerable<Allergie>>> GetAllergies()
{
if (_context.Allergies == null)
{
return NotFound();
}
return await _context.Allergies.ToListAsync();
}
// GET: api/Allergien/5
[HttpGet("{id}")]
public async Task<ActionResult<Allergie>> GetAllergie(int id)
{
if (_context.Allergies == null)
{
return NotFound();
}
var allergie = await _context.Allergies.FindAsync(id);
if (allergie == null)
{
return NotFound();
}
return allergie;
}
// PUT: api/Allergien/5
// To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754
[HttpPut("{id}")]
public async Task<IActionResult> PutAllergie(int id, Allergie allergie)
{
if (id != allergie.Idallergie)
{
return BadRequest();
}
_context.Entry(allergie).State = EntityState.Modified;
try
{
await _context.SaveChangesAsync();
}
catch (DbUpdateConcurrencyException)
{
if (!AllergieExists(id))
{
return NotFound();
}
else
{
throw;
}
}
return NoContent();
}
// POST: api/Allergien
// To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754
[HttpPost]
public async Task<ActionResult<Allergie>> PostAllergie(Allergie allergie)
{
if (_context.Allergies == null)
{
return Problem("Entity set 'WebApiContext.Allergies' is null.");
}
_context.Allergies.Add(allergie);
try
{
await _context.SaveChangesAsync();
}
catch (DbUpdateException)
{
if (AllergieExists(allergie.Idallergie))
{
return Conflict();
}
else
{
throw;
}
}
return CreatedAtAction("GetAllergie", new { id = allergie.Idallergie }, allergie);
}
// DELETE: api/Allergien/5
[HttpDelete("{id}")]
public async Task<IActionResult> DeleteAllergie(int id)
{
if (_context.Allergies == null)
{
return NotFound();
}
var allergie = await _context.Allergies.FindAsync(id);
if (allergie == null)
{
return NotFound();
}
_context.Allergies.Remove(allergie);
await _context.SaveChangesAsync();
return NoContent();
}
private bool AllergieExists(int id)
{
return (_context.Allergies?.Any(e => e.Idallergie == id)).GetValueOrDefault();
}
}
}

View File

@ -0,0 +1,138 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using WebApi.Data;
using WebApi.Models;
namespace WebApi.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class BestellungspositionenController : ControllerBase
{
private readonly WebApiContext _context;
public BestellungspositionenController(WebApiContext context)
{
_context = context;
}
// GET: api/Bestellungspositionen
[HttpGet]
public async Task<ActionResult<IEnumerable<Bestellungsposition>>> GetBestellungspositions()
{
if (_context.Bestellungspositions == null)
{
return NotFound();
}
return await _context.Bestellungspositions.ToListAsync();
}
// GET: api/Bestellungspositionen/5
[HttpGet("{id}")]
public async Task<ActionResult<Bestellungsposition>> GetBestellungsposition(int id)
{
if (_context.Bestellungspositions == null)
{
return NotFound();
}
var bestellungsposition = await _context.Bestellungspositions.FindAsync(id);
if (bestellungsposition == null)
{
return NotFound();
}
return bestellungsposition;
}
// PUT: api/Bestellungspositionen/5
// To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754
[HttpPut("{id}")]
public async Task<IActionResult> PutBestellungsposition(int id, Bestellungsposition bestellungsposition)
{
if (id != bestellungsposition.Idbestellung)
{
return BadRequest();
}
_context.Entry(bestellungsposition).State = EntityState.Modified;
try
{
await _context.SaveChangesAsync();
}
catch (DbUpdateConcurrencyException)
{
if (!BestellungspositionExists(id))
{
return NotFound();
}
else
{
throw;
}
}
return NoContent();
}
// POST: api/Bestellungspositionen
// To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754
[HttpPost]
public async Task<ActionResult<Bestellungsposition>> PostBestellungsposition(Bestellungsposition bestellungsposition)
{
if (_context.Bestellungspositions == null)
{
return Problem("Entity set 'WebApiContext.Bestellungspositions' is null.");
}
_context.Bestellungspositions.Add(bestellungsposition);
try
{
await _context.SaveChangesAsync();
}
catch (DbUpdateException)
{
if (BestellungspositionExists(bestellungsposition.Idbestellung))
{
return Conflict();
}
else
{
throw;
}
}
return CreatedAtAction("GetBestellungsposition", new { id = bestellungsposition.Idbestellung }, bestellungsposition);
}
// DELETE: api/Bestellungspositionen/5
[HttpDelete("{id}")]
public async Task<IActionResult> DeleteBestellungsposition(int id)
{
if (_context.Bestellungspositions == null)
{
return NotFound();
}
var bestellungsposition = await _context.Bestellungspositions.FindAsync(id);
if (bestellungsposition == null)
{
return NotFound();
}
_context.Bestellungspositions.Remove(bestellungsposition);
await _context.SaveChangesAsync();
return NoContent();
}
private bool BestellungspositionExists(int id)
{
return (_context.Bestellungspositions?.Any(e => e.Idbestellung == id)).GetValueOrDefault();
}
}
}

View File

@ -0,0 +1,138 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using WebApi.Data;
using WebApi.Models;
namespace WebApi.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class KundenController : ControllerBase
{
private readonly WebApiContext _context;
public KundenController(WebApiContext context)
{
_context = context;
}
// GET: api/Kunden
[HttpGet]
public async Task<ActionResult<IEnumerable<Kunde>>> GetKundes()
{
if (_context.Kundes == null)
{
return NotFound();
}
return await _context.Kundes.ToListAsync();
}
// GET: api/Kunden/5
[HttpGet("{id}")]
public async Task<ActionResult<Kunde>> GetKunde(int id)
{
if (_context.Kundes == null)
{
return NotFound();
}
var kunde = await _context.Kundes.FindAsync(id);
if (kunde == null)
{
return NotFound();
}
return kunde;
}
// PUT: api/Kunden/5
// To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754
[HttpPut("{id}")]
public async Task<IActionResult> PutKunde(int id, Kunde kunde)
{
if (id != kunde.Idkunde)
{
return BadRequest();
}
_context.Entry(kunde).State = EntityState.Modified;
try
{
await _context.SaveChangesAsync();
}
catch (DbUpdateConcurrencyException)
{
if (!KundeExists(id))
{
return NotFound();
}
else
{
throw;
}
}
return NoContent();
}
// POST: api/Kunden
// To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754
[HttpPost]
public async Task<ActionResult<Kunde>> PostKunde(Kunde kunde)
{
if (_context.Kundes == null)
{
return Problem("Entity set 'WebApiContext.Kundes' is null.");
}
_context.Kundes.Add(kunde);
try
{
await _context.SaveChangesAsync();
}
catch (DbUpdateException)
{
if (KundeExists(kunde.Idkunde))
{
return Conflict();
}
else
{
throw;
}
}
return CreatedAtAction("GetKunde", new { id = kunde.Idkunde }, kunde);
}
// DELETE: api/Kunden/5
[HttpDelete("{id}")]
public async Task<IActionResult> DeleteKunde(int id)
{
if (_context.Kundes == null)
{
return NotFound();
}
var kunde = await _context.Kundes.FindAsync(id);
if (kunde == null)
{
return NotFound();
}
_context.Kundes.Remove(kunde);
await _context.SaveChangesAsync();
return NoContent();
}
private bool KundeExists(int id)
{
return (_context.Kundes?.Any(e => e.Idkunde == id)).GetValueOrDefault();
}
}
}

View File

@ -0,0 +1,138 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using WebApi.Data;
using WebApi.Models;
namespace WebApi.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class MenuitemkategoriesController : ControllerBase
{
private readonly WebApiContext _context;
public MenuitemkategoriesController(WebApiContext context)
{
_context = context;
}
// GET: api/Menuitemkategories
[HttpGet]
public async Task<ActionResult<IEnumerable<Menuitemkategorie>>> GetMenuitemkategories()
{
if (_context.Menuitemkategories == null)
{
return NotFound();
}
return await _context.Menuitemkategories.ToListAsync();
}
// GET: api/Menuitemkategories/5
[HttpGet("{id}")]
public async Task<ActionResult<Menuitemkategorie>> GetMenuitemkategorie(int id)
{
if (_context.Menuitemkategories == null)
{
return NotFound();
}
var menuitemkategorie = await _context.Menuitemkategories.FindAsync(id);
if (menuitemkategorie == null)
{
return NotFound();
}
return menuitemkategorie;
}
// PUT: api/Menuitemkategories/5
// To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754
[HttpPut("{id}")]
public async Task<IActionResult> PutMenuitemkategorie(int id, Menuitemkategorie menuitemkategorie)
{
if (id != menuitemkategorie.IdmenuItemKategorie)
{
return BadRequest();
}
_context.Entry(menuitemkategorie).State = EntityState.Modified;
try
{
await _context.SaveChangesAsync();
}
catch (DbUpdateConcurrencyException)
{
if (!MenuitemkategorieExists(id))
{
return NotFound();
}
else
{
throw;
}
}
return NoContent();
}
// POST: api/Menuitemkategories
// To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754
[HttpPost]
public async Task<ActionResult<Menuitemkategorie>> PostMenuitemkategorie(Menuitemkategorie menuitemkategorie)
{
if (_context.Menuitemkategories == null)
{
return Problem("Entity set 'WebApiContext.Menuitemkategories' is null.");
}
_context.Menuitemkategories.Add(menuitemkategorie);
try
{
await _context.SaveChangesAsync();
}
catch (DbUpdateException)
{
if (MenuitemkategorieExists(menuitemkategorie.IdmenuItemKategorie))
{
return Conflict();
}
else
{
throw;
}
}
return CreatedAtAction("GetMenuitemkategorie", new { id = menuitemkategorie.IdmenuItemKategorie }, menuitemkategorie);
}
// DELETE: api/Menuitemkategories/5
[HttpDelete("{id}")]
public async Task<IActionResult> DeleteMenuitemkategorie(int id)
{
if (_context.Menuitemkategories == null)
{
return NotFound();
}
var menuitemkategorie = await _context.Menuitemkategories.FindAsync(id);
if (menuitemkategorie == null)
{
return NotFound();
}
_context.Menuitemkategories.Remove(menuitemkategorie);
await _context.SaveChangesAsync();
return NoContent();
}
private bool MenuitemkategorieExists(int id)
{
return (_context.Menuitemkategories?.Any(e => e.IdmenuItemKategorie == id)).GetValueOrDefault();
}
}
}

View File

@ -0,0 +1,138 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using WebApi.Data;
using WebApi.Models;
namespace WebApi.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class MenuitemsController : ControllerBase
{
private readonly WebApiContext _context;
public MenuitemsController(WebApiContext context)
{
_context = context;
}
// GET: api/Menuitems
[HttpGet]
public async Task<ActionResult<IEnumerable<Menuitem>>> GetMenuitems()
{
if (_context.Menuitems == null)
{
return NotFound();
}
return await _context.Menuitems.ToListAsync();
}
// GET: api/Menuitems/5
[HttpGet("{id}")]
public async Task<ActionResult<Menuitem>> GetMenuitem(int id)
{
if (_context.Menuitems == null)
{
return NotFound();
}
var menuitem = await _context.Menuitems.FindAsync(id);
if (menuitem == null)
{
return NotFound();
}
return menuitem;
}
// PUT: api/Menuitems/5
// To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754
[HttpPut("{id}")]
public async Task<IActionResult> PutMenuitem(int id, Menuitem menuitem)
{
if (id != menuitem.IdmenuItem)
{
return BadRequest();
}
_context.Entry(menuitem).State = EntityState.Modified;
try
{
await _context.SaveChangesAsync();
}
catch (DbUpdateConcurrencyException)
{
if (!MenuitemExists(id))
{
return NotFound();
}
else
{
throw;
}
}
return NoContent();
}
// POST: api/Menuitems
// To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754
[HttpPost]
public async Task<ActionResult<Menuitem>> PostMenuitem(Menuitem menuitem)
{
if (_context.Menuitems == null)
{
return Problem("Entity set 'WebApiContext.Menuitems' is null.");
}
_context.Menuitems.Add(menuitem);
try
{
await _context.SaveChangesAsync();
}
catch (DbUpdateException)
{
if (MenuitemExists(menuitem.IdmenuItem))
{
return Conflict();
}
else
{
throw;
}
}
return CreatedAtAction("GetMenuitem", new { id = menuitem.IdmenuItem }, menuitem);
}
// DELETE: api/Menuitems/5
[HttpDelete("{id}")]
public async Task<IActionResult> DeleteMenuitem(int id)
{
if (_context.Menuitems == null)
{
return NotFound();
}
var menuitem = await _context.Menuitems.FindAsync(id);
if (menuitem == null)
{
return NotFound();
}
_context.Menuitems.Remove(menuitem);
await _context.SaveChangesAsync();
return NoContent();
}
private bool MenuitemExists(int id)
{
return (_context.Menuitems?.Any(e => e.IdmenuItem == id)).GetValueOrDefault();
}
}
}

View File

@ -0,0 +1,138 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using WebApi.Data;
using WebApi.Models;
namespace WebApi.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class MenuitemueberkategoriesController : ControllerBase
{
private readonly WebApiContext _context;
public MenuitemueberkategoriesController(WebApiContext context)
{
_context = context;
}
// GET: api/Menuitemueberkategories
[HttpGet]
public async Task<ActionResult<IEnumerable<Menuitemueberkategorie>>> GetMenuitemueberkategories()
{
if (_context.Menuitemueberkategories == null)
{
return NotFound();
}
return await _context.Menuitemueberkategories.ToListAsync();
}
// GET: api/Menuitemueberkategories/5
[HttpGet("{id}")]
public async Task<ActionResult<Menuitemueberkategorie>> GetMenuitemueberkategorie(int id)
{
if (_context.Menuitemueberkategories == null)
{
return NotFound();
}
var menuitemueberkategorie = await _context.Menuitemueberkategories.FindAsync(id);
if (menuitemueberkategorie == null)
{
return NotFound();
}
return menuitemueberkategorie;
}
// PUT: api/Menuitemueberkategories/5
// To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754
[HttpPut("{id}")]
public async Task<IActionResult> PutMenuitemueberkategorie(int id, Menuitemueberkategorie menuitemueberkategorie)
{
if (id != menuitemueberkategorie.IdmenuItemUeberkategorie)
{
return BadRequest();
}
_context.Entry(menuitemueberkategorie).State = EntityState.Modified;
try
{
await _context.SaveChangesAsync();
}
catch (DbUpdateConcurrencyException)
{
if (!MenuitemueberkategorieExists(id))
{
return NotFound();
}
else
{
throw;
}
}
return NoContent();
}
// POST: api/Menuitemueberkategories
// To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754
[HttpPost]
public async Task<ActionResult<Menuitemueberkategorie>> PostMenuitemueberkategorie(Menuitemueberkategorie menuitemueberkategorie)
{
if (_context.Menuitemueberkategories == null)
{
return Problem("Entity set 'WebApiContext.Menuitemueberkategories' is null.");
}
_context.Menuitemueberkategories.Add(menuitemueberkategorie);
try
{
await _context.SaveChangesAsync();
}
catch (DbUpdateException)
{
if (MenuitemueberkategorieExists(menuitemueberkategorie.IdmenuItemUeberkategorie))
{
return Conflict();
}
else
{
throw;
}
}
return CreatedAtAction("GetMenuitemueberkategorie", new { id = menuitemueberkategorie.IdmenuItemUeberkategorie }, menuitemueberkategorie);
}
// DELETE: api/Menuitemueberkategories/5
[HttpDelete("{id}")]
public async Task<IActionResult> DeleteMenuitemueberkategorie(int id)
{
if (_context.Menuitemueberkategories == null)
{
return NotFound();
}
var menuitemueberkategorie = await _context.Menuitemueberkategories.FindAsync(id);
if (menuitemueberkategorie == null)
{
return NotFound();
}
_context.Menuitemueberkategories.Remove(menuitemueberkategorie);
await _context.SaveChangesAsync();
return NoContent();
}
private bool MenuitemueberkategorieExists(int id)
{
return (_context.Menuitemueberkategories?.Any(e => e.IdmenuItemUeberkategorie == id)).GetValueOrDefault();
}
}
}

View File

@ -0,0 +1,138 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using WebApi.Data;
using WebApi.Models;
namespace WebApi.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class RabatteController : ControllerBase
{
private readonly WebApiContext _context;
public RabatteController(WebApiContext context)
{
_context = context;
}
// GET: api/Rabatte
[HttpGet]
public async Task<ActionResult<IEnumerable<Rabatt>>> GetRabatts()
{
if (_context.Rabatts == null)
{
return NotFound();
}
return await _context.Rabatts.ToListAsync();
}
// GET: api/Rabatte/5
[HttpGet("{id}")]
public async Task<ActionResult<Rabatt>> GetRabatt(int id)
{
if (_context.Rabatts == null)
{
return NotFound();
}
var rabatt = await _context.Rabatts.FindAsync(id);
if (rabatt == null)
{
return NotFound();
}
return rabatt;
}
// PUT: api/Rabatte/5
// To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754
[HttpPut("{id}")]
public async Task<IActionResult> PutRabatt(int id, Rabatt rabatt)
{
if (id != rabatt.Idrabatt)
{
return BadRequest();
}
_context.Entry(rabatt).State = EntityState.Modified;
try
{
await _context.SaveChangesAsync();
}
catch (DbUpdateConcurrencyException)
{
if (!RabattExists(id))
{
return NotFound();
}
else
{
throw;
}
}
return NoContent();
}
// POST: api/Rabatte
// To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754
[HttpPost]
public async Task<ActionResult<Rabatt>> PostRabatt(Rabatt rabatt)
{
if (_context.Rabatts == null)
{
return Problem("Entity set 'WebApiContext.Rabatts' is null.");
}
_context.Rabatts.Add(rabatt);
try
{
await _context.SaveChangesAsync();
}
catch (DbUpdateException)
{
if (RabattExists(rabatt.Idrabatt))
{
return Conflict();
}
else
{
throw;
}
}
return CreatedAtAction("GetRabatt", new { id = rabatt.Idrabatt }, rabatt);
}
// DELETE: api/Rabatte/5
[HttpDelete("{id}")]
public async Task<IActionResult> DeleteRabatt(int id)
{
if (_context.Rabatts == null)
{
return NotFound();
}
var rabatt = await _context.Rabatts.FindAsync(id);
if (rabatt == null)
{
return NotFound();
}
_context.Rabatts.Remove(rabatt);
await _context.SaveChangesAsync();
return NoContent();
}
private bool RabattExists(int id)
{
return (_context.Rabatts?.Any(e => e.Idrabatt == id)).GetValueOrDefault();
}
}
}

View File

@ -0,0 +1,230 @@
using System;
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore;
using WebApi.Models;
namespace WebApi.Data;
public partial class WebApiContext : DbContext
{
public WebApiContext(DbContextOptions<WebApiContext> options)
: base(options)
{
}
public virtual DbSet<Allergie> Allergies { get; set; }
public virtual DbSet<Bestellungsposition> Bestellungspositions { get; set; }
public virtual DbSet<Kunde> Kundes { get; set; }
public virtual DbSet<Menuitem> Menuitems { get; set; }
public virtual DbSet<Menuitemkategorie> Menuitemkategories { get; set; }
public virtual DbSet<Menuitemueberkategorie> Menuitemueberkategories { get; set; }
public virtual DbSet<Rabatt> Rabatts { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder
.UseCollation("utf8_general_ci")
.HasCharSet("utf8");
modelBuilder.Entity<Allergie>(entity =>
{
entity.HasKey(e => e.Idallergie).HasName("PRIMARY");
entity.ToTable("allergie");
entity.Property(e => e.Idallergie)
.ValueGeneratedNever()
.HasColumnType("int(11)")
.HasColumnName("IDAllergie");
entity.Property(e => e.Beschreibung).HasMaxLength(45);
});
modelBuilder.Entity<Bestellungsposition>(entity =>
{
entity.HasKey(e => e.Idbestellung).HasName("PRIMARY");
entity.ToTable("bestellungsposition");
entity.HasIndex(e => e.KundeIdkunde, "fk_Bestellung_Kunde");
entity.HasIndex(e => e.RabattIdrabatt, "fk_Bestellungsposition_Rabatt1");
entity.Property(e => e.Idbestellung)
.ValueGeneratedNever()
.HasColumnType("int(11)")
.HasColumnName("IDBestellung");
entity.Property(e => e.Datum).HasColumnType("datetime");
entity.Property(e => e.KundeIdkunde)
.HasColumnType("int(11)")
.HasColumnName("Kunde_IDKunde");
entity.Property(e => e.Menge).HasColumnType("int(11)");
entity.Property(e => e.RabattIdrabatt)
.HasColumnType("int(11)")
.HasColumnName("Rabatt_IDRabatt");
entity.HasOne(d => d.KundeIdkundeNavigation).WithMany(p => p.Bestellungspositions)
.HasForeignKey(d => d.KundeIdkunde)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("fk_Bestellung_Kunde");
entity.HasOne(d => d.RabattIdrabattNavigation).WithMany(p => p.Bestellungspositions)
.HasForeignKey(d => d.RabattIdrabatt)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("fk_Bestellungsposition_Rabatt1");
entity.HasMany(d => d.MenuItemIdmenuItems).WithMany(p => p.BestellungspositionIdbestellungs)
.UsingEntity<Dictionary<string, object>>(
"BestellungspositionHasMenuitem",
r => r.HasOne<Menuitem>().WithMany()
.HasForeignKey("MenuItemIdmenuItem")
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("fk_Bestellungsposition_has_MenuItem_MenuItem1"),
l => l.HasOne<Bestellungsposition>().WithMany()
.HasForeignKey("BestellungspositionIdbestellung")
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("fk_Bestellungsposition_has_MenuItem_Bestellungsposition1"),
j =>
{
j.HasKey("BestellungspositionIdbestellung", "MenuItemIdmenuItem")
.HasName("PRIMARY")
.HasAnnotation("MySql:IndexPrefixLength", new[] { 0, 0 });
j.ToTable("bestellungsposition_has_menuitem");
j.HasIndex(new[] { "MenuItemIdmenuItem" }, "fk_Bestellungsposition_has_MenuItem_MenuItem1");
j.IndexerProperty<int>("BestellungspositionIdbestellung")
.HasColumnType("int(11)")
.HasColumnName("Bestellungsposition_IDBestellung");
j.IndexerProperty<int>("MenuItemIdmenuItem")
.HasColumnType("int(11)")
.HasColumnName("MenuItem_IDMenuItem");
});
});
modelBuilder.Entity<Kunde>(entity =>
{
entity.HasKey(e => e.Idkunde).HasName("PRIMARY");
entity.ToTable("kunde");
entity.Property(e => e.Idkunde)
.ValueGeneratedNever()
.HasColumnType("int(11)")
.HasColumnName("IDKunde");
entity.Property(e => e.Code)
.HasMaxLength(45)
.HasColumnName("code");
entity.Property(e => e.Treuepunkte).HasColumnType("int(11)");
});
modelBuilder.Entity<Menuitem>(entity =>
{
entity.HasKey(e => e.IdmenuItem).HasName("PRIMARY");
entity.ToTable("menuitem");
entity.HasIndex(e => e.MenuItemKategorieIdmenuItemKategorie, "fk_MenuItem_MenuItemKategorie1");
entity.Property(e => e.IdmenuItem)
.ValueGeneratedNever()
.HasColumnType("int(11)")
.HasColumnName("IDMenuItem");
entity.Property(e => e.Bezeichnung).HasMaxLength(45);
entity.Property(e => e.MenuItemKategorieIdmenuItemKategorie)
.HasColumnType("int(11)")
.HasColumnName("MenuItemKategorie_IDMenuItemKategorie");
entity.Property(e => e.Preis).HasPrecision(8, 2);
entity.Property(e => e.Zusatzinformation).HasMaxLength(45);
entity.HasOne(d => d.MenuItemKategorieIdmenuItemKategorieNavigation).WithMany(p => p.Menuitems)
.HasForeignKey(d => d.MenuItemKategorieIdmenuItemKategorie)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("fk_MenuItem_MenuItemKategorie1");
entity.HasMany(d => d.AllergieIdallergies).WithMany(p => p.MenuItemIdmenuItems)
.UsingEntity<Dictionary<string, object>>(
"MenuitemHasAllergie",
r => r.HasOne<Allergie>().WithMany()
.HasForeignKey("AllergieIdallergie")
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("fk_MenuItem_has_Allergie_Allergie1"),
l => l.HasOne<Menuitem>().WithMany()
.HasForeignKey("MenuItemIdmenuItem")
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("fk_MenuItem_has_Allergie_MenuItem1"),
j =>
{
j.HasKey("MenuItemIdmenuItem", "AllergieIdallergie")
.HasName("PRIMARY")
.HasAnnotation("MySql:IndexPrefixLength", new[] { 0, 0 });
j.ToTable("menuitem_has_allergie");
j.HasIndex(new[] { "AllergieIdallergie" }, "fk_MenuItem_has_Allergie_Allergie1");
j.IndexerProperty<int>("MenuItemIdmenuItem")
.HasColumnType("int(11)")
.HasColumnName("MenuItem_IDMenuItem");
j.IndexerProperty<int>("AllergieIdallergie")
.HasColumnType("int(11)")
.HasColumnName("Allergie_IDAllergie");
});
});
modelBuilder.Entity<Menuitemkategorie>(entity =>
{
entity.HasKey(e => e.IdmenuItemKategorie).HasName("PRIMARY");
entity.ToTable("menuitemkategorie");
entity.HasIndex(e => e.MenuItemUeberkategorieIdmenuItemUeberkategorie, "fk_MenuItemKategorie_MenuItemUeberkategorie1");
entity.Property(e => e.IdmenuItemKategorie)
.ValueGeneratedNever()
.HasColumnType("int(11)")
.HasColumnName("IDMenuItemKategorie");
entity.Property(e => e.Bezeichnung).HasMaxLength(45);
entity.Property(e => e.MenuItemUeberkategorieIdmenuItemUeberkategorie)
.HasColumnType("int(11)")
.HasColumnName("MenuItemUeberkategorie_IDMenuItemUeberkategorie");
entity.HasOne(d => d.MenuItemUeberkategorieIdmenuItemUeberkategorieNavigation).WithMany(p => p.Menuitemkategories)
.HasForeignKey(d => d.MenuItemUeberkategorieIdmenuItemUeberkategorie)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("fk_MenuItemKategorie_MenuItemUeberkategorie1");
});
modelBuilder.Entity<Menuitemueberkategorie>(entity =>
{
entity.HasKey(e => e.IdmenuItemUeberkategorie).HasName("PRIMARY");
entity.ToTable("menuitemueberkategorie");
entity.Property(e => e.IdmenuItemUeberkategorie)
.ValueGeneratedNever()
.HasColumnType("int(11)")
.HasColumnName("IDMenuItemUeberkategorie");
entity.Property(e => e.Bezeichnung).HasMaxLength(45);
});
modelBuilder.Entity<Rabatt>(entity =>
{
entity.HasKey(e => e.Idrabatt).HasName("PRIMARY");
entity.ToTable("rabatt");
entity.Property(e => e.Idrabatt)
.ValueGeneratedNever()
.HasColumnType("int(11)")
.HasColumnName("IDRabatt");
entity.Property(e => e.GueltigkeitBis).HasColumnType("datetime");
entity.Property(e => e.GueltigkeitVon).HasColumnType("datetime");
entity.Property(e => e.Prozent).HasPrecision(8, 2);
});
OnModelCreatingPartial(modelBuilder);
}
partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
}

View File

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
namespace WebApi.Models;
public partial class Allergie
{
public int Idallergie { get; set; }
public string? Beschreibung { get; set; }
public virtual ICollection<Menuitem> MenuItemIdmenuItems { get; set; } = new List<Menuitem>();
}

View File

@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
namespace WebApi.Models;
public partial class Bestellungsposition
{
public int Idbestellung { get; set; }
public int? Menge { get; set; }
public DateTime? Datum { get; set; }
public int KundeIdkunde { get; set; }
public int RabattIdrabatt { get; set; }
public virtual Kunde KundeIdkundeNavigation { get; set; } = null!;
public virtual Rabatt RabattIdrabattNavigation { get; set; } = null!;
public virtual ICollection<Menuitem> MenuItemIdmenuItems { get; set; } = new List<Menuitem>();
}

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
namespace WebApi.Models;
public partial class Kunde
{
public int Idkunde { get; set; }
public string? Code { get; set; }
public int? Treuepunkte { get; set; }
public virtual ICollection<Bestellungsposition> Bestellungspositions { get; set; } = new List<Bestellungsposition>();
}

View File

@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
namespace WebApi.Models;
public partial class Menuitem
{
public int IdmenuItem { get; set; }
public string? Bezeichnung { get; set; }
public string? Zusatzinformation { get; set; }
public decimal? Preis { get; set; }
public int MenuItemKategorieIdmenuItemKategorie { get; set; }
public virtual Menuitemkategorie MenuItemKategorieIdmenuItemKategorieNavigation { get; set; } = null!;
public virtual ICollection<Allergie> AllergieIdallergies { get; set; } = new List<Allergie>();
public virtual ICollection<Bestellungsposition> BestellungspositionIdbestellungs { get; set; } = new List<Bestellungsposition>();
}

View File

@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
namespace WebApi.Models;
public partial class Menuitemkategorie
{
public int IdmenuItemKategorie { get; set; }
public string? Bezeichnung { get; set; }
public int MenuItemUeberkategorieIdmenuItemUeberkategorie { get; set; }
public virtual Menuitemueberkategorie MenuItemUeberkategorieIdmenuItemUeberkategorieNavigation { get; set; } = null!;
public virtual ICollection<Menuitem> Menuitems { get; set; } = new List<Menuitem>();
}

View File

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
namespace WebApi.Models;
public partial class Menuitemueberkategorie
{
public int IdmenuItemUeberkategorie { get; set; }
public string? Bezeichnung { get; set; }
public virtual ICollection<Menuitemkategorie> Menuitemkategories { get; set; } = new List<Menuitemkategorie>();
}

View File

@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
namespace WebApi.Models;
public partial class Rabatt
{
public int Idrabatt { get; set; }
public decimal? Prozent { get; set; }
public DateTime? GueltigkeitVon { get; set; }
public DateTime? GueltigkeitBis { get; set; }
public virtual ICollection<Bestellungsposition> Bestellungspositions { get; set; } = new List<Bestellungsposition>();
}

44
src/WebApi/Program.cs Normal file
View File

@ -0,0 +1,44 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.Net.Http.Headers;
using WebApi.Data;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddDbContext<WebApiContext>(options =>
{
options.UseMySql(builder.Configuration.GetConnectionString("Y4FDB"),
Microsoft.EntityFrameworkCore.ServerVersion.Parse("8.0.23-mysql"));
});
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
//ip:port from y4f
app.UseCors(policy =>
policy.WithOrigins("http://localhost:5248", "https://localhost:7138")
.AllowAnyMethod()
.WithHeaders(HeaderNames.ContentType)
);
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.Run();

View File

@ -0,0 +1,41 @@
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:38447",
"sslPort": 44303
}
},
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "http://localhost:5226",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "https://localhost:7076;http://localhost:5226",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}

0
src/WebApi/README.md Normal file
View File

24
src/WebApi/WebApi.csproj Normal file
View File

@ -0,0 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="7.0.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="7.0.6" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="7.0.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}

View File

@ -0,0 +1,12 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*",
"ConnectionStrings": {
"Y4FDB": "Server=localhost;Database=y4f;Uid=user;Pwd=user"
}
}

View File

@ -1,49 +1,49 @@

.tg {
border-collapse: collapse;
border-spacing: 0;
margin-left: auto;
margin-right: auto;
}
.tg td {
border-color: black;
border-style: solid;
border-width: 1px;
font-family: Arial, sans-serif;
font-size: 18px;
overflow: hidden;
padding: 10px 5px;
word-break: normal;
}
.tg th {
border-color: black;
border-style: solid;
border-width: 1px;
font-family: Arial, sans-serif;
font-size: 18px;
font-weight: normal;
overflow: hidden;
padding: 10px 5px;
word-break: normal;
}
.tg .tg-c3ow {
border-color: inherit;
text-align: center;
vertical-align: center;
}
.tg .tg-0pky {
border-color: inherit;
text-align: center;
vertical-align: center;
}
.icon {
width: 100%;
max-width: 100px;
height: auto;
}

.tg {
border-collapse: collapse;
border-spacing: 0;
margin-left: auto;
margin-right: auto;
}
.tg td {
border-color: black;
border-style: solid;
border-width: 1px;
font-family: Arial, sans-serif;
font-size: 18px;
overflow: hidden;
padding: 10px 5px;
word-break: normal;
}
.tg th {
border-color: black;
border-style: solid;
border-width: 1px;
font-family: Arial, sans-serif;
font-size: 18px;
font-weight: normal;
overflow: hidden;
padding: 10px 5px;
word-break: normal;
}
.tg .tg-c3ow {
border-color: inherit;
text-align: center;
vertical-align: center;
}
.tg .tg-0pky {
border-color: inherit;
text-align: center;
vertical-align: center;
}
.icon {
width: 100%;
max-width: 100px;
height: auto;
}

View File

@ -0,0 +1,51 @@
@page "/TestFetchAllergienData"
@inject HttpClient Http
<PageTitle>Allergien</PageTitle>
<h1>Allergien</h1>
<p>This component demonstrates fetching data from the mysql server.</p>
@if (allergien == null)
{
<p><em>Loading...</em></p>
}
else
{
<table class="table">
<thead>
<tr>
<th>ID</th>
<th>Beschreibung</th>
</tr>
</thead>
<tbody>
@foreach (var allergie in allergien)
{
<tr>
<td>@allergie.Idallergie</td>
<td>@allergie.Beschreibung</td>
</tr>
}
</tbody>
</table>
}
@code {
private const string ServiceEndpoint = "https://localhost:7076/api/Allergien";
private Allergie[]? allergien;
protected override async Task OnInitializedAsync()
{
allergien = await Http.GetFromJsonAsync<Allergie[]>(ServiceEndpoint);
}
public partial class Allergie
{
public int Idallergie { get; set; }
public string? Beschreibung { get; set; }
}
}

1
src/y4f/README.md Normal file
View File

@ -0,0 +1 @@
# y4f

View File

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 18 KiB

View File

Before

Width:  |  Height:  |  Size: 62 KiB

After

Width:  |  Height:  |  Size: 62 KiB

View File

Before

Width:  |  Height:  |  Size: 4.7 KiB

After

Width:  |  Height:  |  Size: 4.7 KiB

View File

Before

Width:  |  Height:  |  Size: 313 KiB

After

Width:  |  Height:  |  Size: 313 KiB

View File

Before

Width:  |  Height:  |  Size: 441 KiB

After

Width:  |  Height:  |  Size: 441 KiB

View File

Before

Width:  |  Height:  |  Size: 243 KiB

After

Width:  |  Height:  |  Size: 243 KiB

View File

Before

Width:  |  Height:  |  Size: 236 KiB

After

Width:  |  Height:  |  Size: 236 KiB

View File

Before

Width:  |  Height:  |  Size: 359 KiB

After

Width:  |  Height:  |  Size: 359 KiB

View File

Before

Width:  |  Height:  |  Size: 395 KiB

After

Width:  |  Height:  |  Size: 395 KiB

View File

Before

Width:  |  Height:  |  Size: 62 KiB

After

Width:  |  Height:  |  Size: 62 KiB

View File

Before

Width:  |  Height:  |  Size: 649 KiB

After

Width:  |  Height:  |  Size: 649 KiB

View File

Before

Width:  |  Height:  |  Size: 430 KiB

After

Width:  |  Height:  |  Size: 430 KiB

View File

Before

Width:  |  Height:  |  Size: 424 KiB

After

Width:  |  Height:  |  Size: 424 KiB

View File

Before

Width:  |  Height:  |  Size: 85 KiB

After

Width:  |  Height:  |  Size: 85 KiB

View File

Before

Width:  |  Height:  |  Size: 234 KiB

After

Width:  |  Height:  |  Size: 234 KiB

View File

Before

Width:  |  Height:  |  Size: 85 KiB

After

Width:  |  Height:  |  Size: 85 KiB

View File

Before

Width:  |  Height:  |  Size: 421 KiB

After

Width:  |  Height:  |  Size: 421 KiB

View File

Before

Width:  |  Height:  |  Size: 54 KiB

After

Width:  |  Height:  |  Size: 54 KiB

View File

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

Before

Width:  |  Height:  |  Size: 2.6 KiB

After

Width:  |  Height:  |  Size: 2.6 KiB

View File

Before

Width:  |  Height:  |  Size: 6.2 KiB

After

Width:  |  Height:  |  Size: 6.2 KiB

View File

@ -3,7 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.4.33205.214
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "y4f", "y4f.csproj", "{1B083D74-9507-4510-A532-8AAAD1FB6035}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "y4f", "src/y4f/y4f.csproj", "{1B083D74-9507-4510-A532-8AAAD1FB6035}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebApi", "src\WebApi\WebApi.csproj", "{2261B5DE-7B90-46FA-9FC2-1924A64BAF3F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -15,6 +17,10 @@ Global
{1B083D74-9507-4510-A532-8AAAD1FB6035}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1B083D74-9507-4510-A532-8AAAD1FB6035}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1B083D74-9507-4510-A532-8AAAD1FB6035}.Release|Any CPU.Build.0 = Release|Any CPU
{2261B5DE-7B90-46FA-9FC2-1924A64BAF3F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2261B5DE-7B90-46FA-9FC2-1924A64BAF3F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2261B5DE-7B90-46FA-9FC2-1924A64BAF3F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2261B5DE-7B90-46FA-9FC2-1924A64BAF3F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE