Datenbank Angelegt über dotnet tools migrations

This commit is contained in:
marcusferl@weifer.de 2022-06-07 14:35:06 +02:00
parent fcb3c844e3
commit a5ce7aa496
98 changed files with 287 additions and 53 deletions

View File

@ -1,39 +0,0 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Aps_Single_Page_Anwendung.Controllers
{
[ApiController]
[Route("[controller]")]
public class WeatherForecastController : ControllerBase
{
private static readonly string[] Summaries = new[]
{
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};
private readonly ILogger<WeatherForecastController> _logger;
public WeatherForecastController(ILogger<WeatherForecastController> logger)
{
_logger = logger;
}
[HttpGet]
public IEnumerable<WeatherForecast> Get()
{
var rng = new Random();
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
{
Date = DateTime.Now.AddDays(index),
TemperatureC = rng.Next(-20, 55),
Summary = Summaries[rng.Next(Summaries.Length)]
})
.ToArray();
}
}
}

View File

@ -1,10 +0,0 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*"
}

View File

@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17 # Visual Studio Version 17
VisualStudioVersion = 17.1.32319.34 VisualStudioVersion = 17.1.32319.34
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Aps Single Page Anwendung", "Aps Single Page Anwendung\Aps Single Page Anwendung.csproj", "{82B23342-82DE-47B8-8FDC-A9477C6897EC}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Single_Page_Anwendung", "Single_Page_Anwendung\Single_Page_Anwendung.csproj", "{82B23342-82DE-47B8-8FDC-A9477C6897EC}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution

View File

@ -0,0 +1,83 @@
// <auto-generated />
using Aps_Single_Page_Anwendung.Models;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace Single_Page_Anwendung.Migrations
{
[DbContext(typeof(FutterContext))]
[Migration("20220607122417_InitialCreate")]
partial class InitialCreate
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "3.0.0")
.HasAnnotation("Relational:MaxIdentifierLength", 128)
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
modelBuilder.Entity("Aps_Single_Page_Anwendung.Models.Kategorie", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
b.Property<string>("Beschreibung")
.HasColumnType("nvarchar(255)")
.HasMaxLength(255);
b.Property<string>("Name")
.HasColumnType("nvarchar(100)")
.HasMaxLength(100);
b.HasKey("Id");
b.ToTable("Kategorien");
});
modelBuilder.Entity("Aps_Single_Page_Anwendung.Models.Speise", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
b.Property<string>("Beschreibung")
.HasColumnType("nvarchar(255)")
.HasMaxLength(255);
b.Property<int>("KategorieId")
.HasColumnType("int");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(100)")
.HasMaxLength(100);
b.Property<double>("Preis")
.HasColumnType("float");
b.HasKey("Id");
b.HasIndex("KategorieId");
b.ToTable("Speisen");
});
modelBuilder.Entity("Aps_Single_Page_Anwendung.Models.Speise", b =>
{
b.HasOne("Aps_Single_Page_Anwendung.Models.Kategorie", "Kategorie")
.WithMany("Speisen")
.HasForeignKey("KategorieId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,60 @@
using Microsoft.EntityFrameworkCore.Migrations;
namespace Single_Page_Anwendung.Migrations
{
public partial class InitialCreate : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Kategorien",
columns: table => new
{
Id = table.Column<int>(nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Name = table.Column<string>(maxLength: 100, nullable: true),
Beschreibung = table.Column<string>(maxLength: 255, nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Kategorien", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Speisen",
columns: table => new
{
Id = table.Column<int>(nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Name = table.Column<string>(maxLength: 100, nullable: false),
Beschreibung = table.Column<string>(maxLength: 255, nullable: true),
Preis = table.Column<double>(nullable: false),
KategorieId = table.Column<int>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Speisen", x => x.Id);
table.ForeignKey(
name: "FK_Speisen_Kategorien_KategorieId",
column: x => x.KategorieId,
principalTable: "Kategorien",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_Speisen_KategorieId",
table: "Speisen",
column: "KategorieId");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Speisen");
migrationBuilder.DropTable(
name: "Kategorien");
}
}
}

View File

@ -0,0 +1,81 @@
// <auto-generated />
using Aps_Single_Page_Anwendung.Models;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace Single_Page_Anwendung.Migrations
{
[DbContext(typeof(FutterContext))]
partial class FutterContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "3.0.0")
.HasAnnotation("Relational:MaxIdentifierLength", 128)
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
modelBuilder.Entity("Aps_Single_Page_Anwendung.Models.Kategorie", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
b.Property<string>("Beschreibung")
.HasColumnType("nvarchar(255)")
.HasMaxLength(255);
b.Property<string>("Name")
.HasColumnType("nvarchar(100)")
.HasMaxLength(100);
b.HasKey("Id");
b.ToTable("Kategorien");
});
modelBuilder.Entity("Aps_Single_Page_Anwendung.Models.Speise", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
b.Property<string>("Beschreibung")
.HasColumnType("nvarchar(255)")
.HasMaxLength(255);
b.Property<int>("KategorieId")
.HasColumnType("int");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(100)")
.HasMaxLength(100);
b.Property<double>("Preis")
.HasColumnType("float");
b.HasKey("Id");
b.HasIndex("KategorieId");
b.ToTable("Speisen");
});
modelBuilder.Entity("Aps_Single_Page_Anwendung.Models.Speise", b =>
{
b.HasOne("Aps_Single_Page_Anwendung.Models.Kategorie", "Kategorie")
.WithMany("Speisen")
.HasForeignKey("KategorieId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,6 @@
namespace Single_Page_Anwendung.Models
{
public class DatenEinlesen
{
}
}

View File

@ -0,0 +1,21 @@
using Microsoft.EntityFrameworkCore;
namespace Aps_Single_Page_Anwendung.Models
{
public class FutterContext : DbContext
{
public FutterContext(DbContextOptions<FutterContext> options) : base(options)
{
}
//Erzeugt eine Tabelle namens Speisen mit den Felder aus Speise (Models)
public DbSet<Speise> Speisen { get; set; }
//Erzeugt eine Tabelle namens Kategorien, mit den Feldern aus Kategorie (Models)
public DbSet<Kategorie> Kategorien { get; set; }
}
}

View File

@ -1,11 +1,17 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
namespace Aps_Single_Page_Anwendung.Models namespace Aps_Single_Page_Anwendung.Models
{ {
public class Kategorie public class Kategorie
{ {
public int Id { get; set; } public int Id { get; set; }
[MaxLength(100)]
public string Name { get; set; } public string Name { get; set; }
[MaxLength(255)]
public string Beschreibung { get; set; } public string Beschreibung { get; set; }
public virtual ICollection<Speise> Speisen { get; set; } = new HashSet<Speise>(); public virtual ICollection<Speise> Speisen { get; set; } = new HashSet<Speise>();
} }

View File

@ -6,8 +6,11 @@ namespace Aps_Single_Page_Anwendung.Models
{ {
public int Id { get; set; } public int Id { get; set; }
[Required] // Leere Felder sind damit nicht möglich [Required] // Leere Felder sind damit nicht möglich, kein null möglich
[MaxLength(100)] // Vermeidet bei des Feldes in der Tabelle ein varchar(Max)
public string Name { get; set; } public string Name { get; set; }
[MaxLength(255)]
public string Beschreibung { get; set; } public string Beschreibung { get; set; }
[Range(0,25)] // Preis darf nur zwischen 0 und 25 Euro sein [Range(0,25)] // Preis darf nur zwischen 0 und 25 Euro sein

View File

@ -10,11 +10,16 @@
<!-- Set this to true if you enable server-side prerendering --> <!-- Set this to true if you enable server-side prerendering -->
<BuildServerSideRenderer>false</BuildServerSideRenderer> <BuildServerSideRenderer>false</BuildServerSideRenderer>
<RootNamespace>Aps_Single_Page_Anwendung</RootNamespace> <RootNamespace>Single_Page_Anwendung</RootNamespace>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.SpaServices.Extensions" Version="3.1.22" /> <PackageReference Include="Microsoft.AspNetCore.SpaServices.Extensions" Version="3.1.22" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.0.0" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@ -1,8 +1,10 @@
using Aps_Single_Page_Anwendung.Models;
using Aps_Single_Page_Anwendung.Repositories; using Aps_Single_Page_Anwendung.Repositories;
using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpsPolicy; using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.AspNetCore.SpaServices.AngularCli; using Microsoft.AspNetCore.SpaServices.AngularCli;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting;
@ -18,9 +20,12 @@ namespace Aps_Single_Page_Anwendung
public IConfiguration Configuration { get; } public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services) public void ConfigureServices(IServiceCollection services)
{ {
// Connection String den ich in der appsettings.json definiert habe
services.AddDbContext<FutterContext>(options => options.UseSqlServer(Configuration.GetConnectionString("FutterContext")));
services.AddControllersWithViews(); services.AddControllersWithViews();
// Sorgt dafür, das jedesmal wenn ein ISpeiseRep angefragt wird, wird ein FileSpeiseRep zurückgegeben // Sorgt dafür, das jedesmal wenn ein ISpeiseRep angefragt wird, wird ein FileSpeiseRep zurückgegeben

View File

@ -0,0 +1,13 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"ConnectionStrings": {
"FutterContext" : "Server=(localdb)\\mssqllocaldb;Database=DaRestaurant;Trusted_Connection=True;MultipleActiveResultSets=True" // Verbindungsstring zur Datenbank, in diesem Fall Local
},
"AllowedHosts": "*"
}

View File

Before

Width:  |  Height:  |  Size: 136 KiB

After

Width:  |  Height:  |  Size: 136 KiB

View File

Before

Width:  |  Height:  |  Size: 104 KiB

After

Width:  |  Height:  |  Size: 104 KiB

View File

Before

Width:  |  Height:  |  Size: 62 KiB

After

Width:  |  Height:  |  Size: 62 KiB

View File

Before

Width:  |  Height:  |  Size: 105 KiB

After

Width:  |  Height:  |  Size: 105 KiB

View File

Before

Width:  |  Height:  |  Size: 99 KiB

After

Width:  |  Height:  |  Size: 99 KiB

View File

Before

Width:  |  Height:  |  Size: 88 KiB

After

Width:  |  Height:  |  Size: 88 KiB

View File

Before

Width:  |  Height:  |  Size: 127 KiB

After

Width:  |  Height:  |  Size: 127 KiB

View File

Before

Width:  |  Height:  |  Size: 86 KiB

After

Width:  |  Height:  |  Size: 86 KiB

View File

Before

Width:  |  Height:  |  Size: 81 KiB

After

Width:  |  Height:  |  Size: 81 KiB

View File

Before

Width:  |  Height:  |  Size: 73 KiB

After

Width:  |  Height:  |  Size: 73 KiB

View File

Before

Width:  |  Height:  |  Size: 103 KiB

After

Width:  |  Height:  |  Size: 103 KiB

View File

Before

Width:  |  Height:  |  Size: 101 KiB

After

Width:  |  Height:  |  Size: 101 KiB

View File

Before

Width:  |  Height:  |  Size: 92 KiB

After

Width:  |  Height:  |  Size: 92 KiB

View File

Before

Width:  |  Height:  |  Size: 67 KiB

After

Width:  |  Height:  |  Size: 67 KiB

View File

Before

Width:  |  Height:  |  Size: 55 KiB

After

Width:  |  Height:  |  Size: 55 KiB

View File

Before

Width:  |  Height:  |  Size: 146 KiB

After

Width:  |  Height:  |  Size: 146 KiB

View File

Before

Width:  |  Height:  |  Size: 65 KiB

After

Width:  |  Height:  |  Size: 65 KiB

View File

Before

Width:  |  Height:  |  Size: 84 KiB

After

Width:  |  Height:  |  Size: 84 KiB

View File

Before

Width:  |  Height:  |  Size: 72 KiB

After

Width:  |  Height:  |  Size: 72 KiB

View File

Before

Width:  |  Height:  |  Size: 71 KiB

After

Width:  |  Height:  |  Size: 71 KiB

View File

Before

Width:  |  Height:  |  Size: 104 KiB

After

Width:  |  Height:  |  Size: 104 KiB

View File

Before

Width:  |  Height:  |  Size: 72 KiB

After

Width:  |  Height:  |  Size: 72 KiB

View File

Before

Width:  |  Height:  |  Size: 89 KiB

After

Width:  |  Height:  |  Size: 89 KiB

View File

Before

Width:  |  Height:  |  Size: 101 KiB

After

Width:  |  Height:  |  Size: 101 KiB

View File

Before

Width:  |  Height:  |  Size: 93 KiB

After

Width:  |  Height:  |  Size: 93 KiB

View File

Before

Width:  |  Height:  |  Size: 113 KiB

After

Width:  |  Height:  |  Size: 113 KiB

View File

Before

Width:  |  Height:  |  Size: 64 KiB

After

Width:  |  Height:  |  Size: 64 KiB

View File

Before

Width:  |  Height:  |  Size: 93 KiB

After

Width:  |  Height:  |  Size: 93 KiB

View File

Before

Width:  |  Height:  |  Size: 31 KiB

After

Width:  |  Height:  |  Size: 31 KiB