mirror of
https://github.com/yummy4friends/y4f.git
synced 2025-07-18 16:25:51 +02:00
WebAPI for database integrity added
Restructure the solution * The project has been split into the database integration "src/webapi" and the Blazor wasm project "src/y4f". WebAPI * API with CRUD capabilities * The main task of the "WebAPI" project is to access the database data and make it available to the Blazor-WASM project via an API. * GET example of the allergy table via the file "TestFetchAllergienData.razor", which can be tested via the browser "/TestFetchAllergienData".
This commit is contained in:
140
src/WebApi/Controllers/AllergienController.cs
Normal file
140
src/WebApi/Controllers/AllergienController.cs
Normal 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();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
138
src/WebApi/Controllers/BestellungspositionenController.cs
Normal file
138
src/WebApi/Controllers/BestellungspositionenController.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
138
src/WebApi/Controllers/KundenController.cs
Normal file
138
src/WebApi/Controllers/KundenController.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
138
src/WebApi/Controllers/MenuitemkategoriesController.cs
Normal file
138
src/WebApi/Controllers/MenuitemkategoriesController.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
138
src/WebApi/Controllers/MenuitemsController.cs
Normal file
138
src/WebApi/Controllers/MenuitemsController.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
138
src/WebApi/Controllers/MenuitemueberkategoriesController.cs
Normal file
138
src/WebApi/Controllers/MenuitemueberkategoriesController.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
138
src/WebApi/Controllers/RabatteController.cs
Normal file
138
src/WebApi/Controllers/RabatteController.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user