mirror of
https://github.com/yummy4friends/y4f.git
synced 2024-12-28 16:08:20 +01:00
Add domainmodell admin (#34)
This commit is contained in:
parent
4b5f0c2b96
commit
e317144914
124
src/WebApi/Controllers/AdminsController.cs
Normal file
124
src/WebApi/Controllers/AdminsController.cs
Normal file
@ -0,0 +1,124 @@
|
|||||||
|
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 AdminsController : ControllerBase
|
||||||
|
{
|
||||||
|
private readonly WebApiContext _context;
|
||||||
|
|
||||||
|
public AdminsController(WebApiContext context)
|
||||||
|
{
|
||||||
|
_context = context;
|
||||||
|
}
|
||||||
|
|
||||||
|
// GET: api/Admins
|
||||||
|
[HttpGet]
|
||||||
|
public async Task<ActionResult<IEnumerable<Admin>>> GetAdmins()
|
||||||
|
{
|
||||||
|
if (_context.Admins == null)
|
||||||
|
{
|
||||||
|
return NotFound();
|
||||||
|
}
|
||||||
|
return await _context.Admins.ToListAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
// GET: api/Admins/5
|
||||||
|
[HttpGet("{id}")]
|
||||||
|
public async Task<ActionResult<Admin>> GetAdmin(int id)
|
||||||
|
{
|
||||||
|
if (_context.Admins == null)
|
||||||
|
{
|
||||||
|
return NotFound();
|
||||||
|
}
|
||||||
|
var admin = await _context.Admins.FindAsync(id);
|
||||||
|
|
||||||
|
if (admin == null)
|
||||||
|
{
|
||||||
|
return NotFound();
|
||||||
|
}
|
||||||
|
|
||||||
|
return admin;
|
||||||
|
}
|
||||||
|
|
||||||
|
// PUT: api/Admins/5
|
||||||
|
// To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754
|
||||||
|
[HttpPut("{id}")]
|
||||||
|
public async Task<IActionResult> PutAdmin(int id, Admin admin)
|
||||||
|
{
|
||||||
|
if (id != admin.Id)
|
||||||
|
{
|
||||||
|
return BadRequest();
|
||||||
|
}
|
||||||
|
|
||||||
|
_context.Entry(admin).State = EntityState.Modified;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
catch (DbUpdateConcurrencyException)
|
||||||
|
{
|
||||||
|
if (!AdminExists(id))
|
||||||
|
{
|
||||||
|
return NotFound();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return NoContent();
|
||||||
|
}
|
||||||
|
|
||||||
|
// POST: api/Admins
|
||||||
|
// To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754
|
||||||
|
[HttpPost]
|
||||||
|
public async Task<ActionResult<Admin>> PostAdmin(Admin admin)
|
||||||
|
{
|
||||||
|
if (_context.Admins == null)
|
||||||
|
{
|
||||||
|
return Problem("Entity set 'WebApiContext.Admins' is null.");
|
||||||
|
}
|
||||||
|
_context.Admins.Add(admin);
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
|
||||||
|
return CreatedAtAction("GetAdmin", new { id = admin.Id }, admin);
|
||||||
|
}
|
||||||
|
|
||||||
|
// DELETE: api/Admins/5
|
||||||
|
[HttpDelete("{id}")]
|
||||||
|
public async Task<IActionResult> DeleteAdmin(int id)
|
||||||
|
{
|
||||||
|
if (_context.Admins == null)
|
||||||
|
{
|
||||||
|
return NotFound();
|
||||||
|
}
|
||||||
|
var admin = await _context.Admins.FindAsync(id);
|
||||||
|
if (admin == null)
|
||||||
|
{
|
||||||
|
return NotFound();
|
||||||
|
}
|
||||||
|
|
||||||
|
_context.Admins.Remove(admin);
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
|
||||||
|
return NoContent();
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool AdminExists(int id)
|
||||||
|
{
|
||||||
|
return (_context.Admins?.Any(e => e.Id == id)).GetValueOrDefault();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -25,8 +25,9 @@ public partial class WebApiContext : DbContext
|
|||||||
public virtual DbSet<Menuitemueberkategorie> Menuitemueberkategories { get; set; }
|
public virtual DbSet<Menuitemueberkategorie> Menuitemueberkategories { get; set; }
|
||||||
|
|
||||||
public virtual DbSet<Rabatt> Rabatts { get; set; }
|
public virtual DbSet<Rabatt> Rabatts { get; set; }
|
||||||
|
public virtual DbSet<Admin> Admins{ get; set; }
|
||||||
|
|
||||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||||
{
|
{
|
||||||
modelBuilder
|
modelBuilder
|
||||||
.UseCollation("utf8_general_ci")
|
.UseCollation("utf8_general_ci")
|
||||||
@ -223,6 +224,12 @@ public partial class WebApiContext : DbContext
|
|||||||
entity.Property(e => e.Prozent).HasPrecision(8, 2);
|
entity.Property(e => e.Prozent).HasPrecision(8, 2);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity<Admin>(entity =>
|
||||||
|
{
|
||||||
|
entity.HasKey(e => e.Id).HasName("PRIMARY");
|
||||||
|
entity.ToTable("admin");
|
||||||
|
});
|
||||||
|
|
||||||
OnModelCreatingPartial(modelBuilder);
|
OnModelCreatingPartial(modelBuilder);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
7
src/WebApi/Models/Admin.cs
Normal file
7
src/WebApi/Models/Admin.cs
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
namespace WebApi.Models;
|
||||||
|
public partial class Admin
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
public string Username { get; set; }
|
||||||
|
public string Password { get; set; }
|
||||||
|
}
|
@ -7,18 +7,19 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="7.0.4" />
|
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="7.0.8" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.5">
|
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.8" />
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.8">
|
||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.5" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.8" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.5">
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.8">
|
||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="7.0.6" />
|
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="7.0.7" />
|
||||||
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="7.0.0" />
|
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="7.0.0" />
|
||||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
|
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
Loading…
Reference in New Issue
Block a user