From 08983ba30d3e3853597bbca819216c54d64c450e Mon Sep 17 00:00:00 2001 From: Gulum Date: Mon, 30 Oct 2023 21:58:56 +0100 Subject: [PATCH] Adjust --- GerbilManagerWebAPI/ApplicationContext.cs | 7 ++++--- .../Controllers/GerbilsController.cs | 4 ++-- .../Controllers/LittersController.cs | 4 ++-- GerbilManagerWebAPI/Dtos/UpdateGerbilDto.cs | 4 ++-- ... 20231030203950_initialCreate.Designer.cs} | 20 +++++++++++-------- ...ate.cs => 20231030203950_initialCreate.cs} | 12 +++++------ .../ApplicationContextModelSnapshot.cs | 16 +++++++++------ 7 files changed, 38 insertions(+), 29 deletions(-) rename GerbilManagerWebAPI/Migrations/{20231023182219_InitialCreate.Designer.cs => 20231030203950_initialCreate.Designer.cs} (84%) rename GerbilManagerWebAPI/Migrations/{20231023182219_InitialCreate.cs => 20231030203950_initialCreate.cs} (92%) diff --git a/GerbilManagerWebAPI/ApplicationContext.cs b/GerbilManagerWebAPI/ApplicationContext.cs index 94926a1..ad30eed 100644 --- a/GerbilManagerWebAPI/ApplicationContext.cs +++ b/GerbilManagerWebAPI/ApplicationContext.cs @@ -8,12 +8,13 @@ public class ApplicationContext : DbContext : base(options) { } - public DbSet Gerbils { get; set; } - public DbSet Litters { get; set; } - public DbSet Breeders { get; set; } protected override void OnModelCreating(ModelBuilder modelBuilder) { + modelBuilder.Entity().ToTable("Gerbils"); + modelBuilder.Entity().ToTable("Litters"); + modelBuilder.Entity().ToTable("Breeders"); + modelBuilder.Entity().HasOne(entity => entity.Litter); modelBuilder.Entity().HasOne(entity => entity.Father); modelBuilder.Entity().HasOne(entity => entity.Mother); diff --git a/GerbilManagerWebAPI/Controllers/GerbilsController.cs b/GerbilManagerWebAPI/Controllers/GerbilsController.cs index 215cd60..88e27a1 100644 --- a/GerbilManagerWebAPI/Controllers/GerbilsController.cs +++ b/GerbilManagerWebAPI/Controllers/GerbilsController.cs @@ -79,8 +79,8 @@ namespace GerbilManagerWebAPI.Controllers } Gerbil updatedGerbil = existingItem with{ - Breeder = unitOfWork.BreederRepository.GetByID(gerbilDto.Breeder.Id), - Litter = unitOfWork.LitterRepository.GetByID(gerbilDto.Litter.Id), + Breeder = unitOfWork.BreederRepository.GetByID(gerbilDto.Breeder), + Litter = unitOfWork.LitterRepository.GetByID(gerbilDto.Litter), Gender = (Gender) (int) gerbilDto.Gender, Name = gerbilDto.Name }; diff --git a/GerbilManagerWebAPI/Controllers/LittersController.cs b/GerbilManagerWebAPI/Controllers/LittersController.cs index c405a49..b746a43 100644 --- a/GerbilManagerWebAPI/Controllers/LittersController.cs +++ b/GerbilManagerWebAPI/Controllers/LittersController.cs @@ -24,7 +24,7 @@ namespace GerbilManagerWebAPI.Controllers [HttpGet] public IEnumerable GetLitters() { - var items = unitOfWork.LitterRepository.Get().Select( litter => litter.AsDto()); + var items = unitOfWork.LitterRepository.Get(includeProperties: "Father,Mother").Select( litter => litter.AsDto()); return items; } @@ -86,7 +86,7 @@ namespace GerbilManagerWebAPI.Controllers unitOfWork.LitterRepository.Update(updatedLitter); this.unitOfWork.Save(); - + return NoContent(); } diff --git a/GerbilManagerWebAPI/Dtos/UpdateGerbilDto.cs b/GerbilManagerWebAPI/Dtos/UpdateGerbilDto.cs index 8ab049d..a132d68 100644 --- a/GerbilManagerWebAPI/Dtos/UpdateGerbilDto.cs +++ b/GerbilManagerWebAPI/Dtos/UpdateGerbilDto.cs @@ -4,7 +4,7 @@ namespace GerbilManagerWebAPI.Dtos { public string? Name { get; init; } public GenderDto? Gender { get; init; } - public LitterDto? Litter { get; init; } - public BreederDto? Breeder { get; init; } + public Guid? Litter { get; init; } + public Guid? Breeder { get; init; } } } \ No newline at end of file diff --git a/GerbilManagerWebAPI/Migrations/20231023182219_InitialCreate.Designer.cs b/GerbilManagerWebAPI/Migrations/20231030203950_initialCreate.Designer.cs similarity index 84% rename from GerbilManagerWebAPI/Migrations/20231023182219_InitialCreate.Designer.cs rename to GerbilManagerWebAPI/Migrations/20231030203950_initialCreate.Designer.cs index e3659af..930b8f3 100644 --- a/GerbilManagerWebAPI/Migrations/20231023182219_InitialCreate.Designer.cs +++ b/GerbilManagerWebAPI/Migrations/20231030203950_initialCreate.Designer.cs @@ -11,8 +11,8 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; namespace GerbilManagerWebAPI.Migrations { [DbContext(typeof(ApplicationContext))] - [Migration("20231023182219_InitialCreate")] - partial class InitialCreate + [Migration("20231030203950_initialCreate")] + partial class initialCreate { /// protected override void BuildTargetModel(ModelBuilder modelBuilder) @@ -31,11 +31,12 @@ namespace GerbilManagerWebAPI.Migrations .HasColumnType("uniqueidentifier"); b.Property("Name") + .IsRequired() .HasColumnType("nvarchar(max)"); b.HasKey("Id"); - b.ToTable("Breeders"); + b.ToTable("Breeders", (string)null); }); modelBuilder.Entity("GerbilManagerWebAPI.Models.Gerbil", b => @@ -47,13 +48,15 @@ namespace GerbilManagerWebAPI.Migrations b.Property("BreederId") .HasColumnType("uniqueidentifier"); - b.Property("Gender") - .HasColumnType("int"); + b.Property("Gender") + .IsRequired() + .HasColumnType("nvarchar(max)"); b.Property("LitterId") .HasColumnType("uniqueidentifier"); b.Property("Name") + .IsRequired() .HasColumnType("nvarchar(max)"); b.HasKey("Id"); @@ -62,7 +65,7 @@ namespace GerbilManagerWebAPI.Migrations b.HasIndex("LitterId"); - b.ToTable("Gerbils"); + b.ToTable("Gerbils", (string)null); }); modelBuilder.Entity("GerbilManagerWebAPI.Models.Litter", b => @@ -81,9 +84,10 @@ namespace GerbilManagerWebAPI.Migrations .HasColumnType("uniqueidentifier"); b.Property("Name") + .IsRequired() .HasColumnType("nvarchar(max)"); - b.Property("Strength") + b.Property("Strength") .HasColumnType("int"); b.HasKey("Id"); @@ -92,7 +96,7 @@ namespace GerbilManagerWebAPI.Migrations b.HasIndex("MotherId"); - b.ToTable("Litters"); + b.ToTable("Litters", (string)null); }); modelBuilder.Entity("GerbilManagerWebAPI.Models.Gerbil", b => diff --git a/GerbilManagerWebAPI/Migrations/20231023182219_InitialCreate.cs b/GerbilManagerWebAPI/Migrations/20231030203950_initialCreate.cs similarity index 92% rename from GerbilManagerWebAPI/Migrations/20231023182219_InitialCreate.cs rename to GerbilManagerWebAPI/Migrations/20231030203950_initialCreate.cs index 540ad6c..ae300ed 100644 --- a/GerbilManagerWebAPI/Migrations/20231023182219_InitialCreate.cs +++ b/GerbilManagerWebAPI/Migrations/20231030203950_initialCreate.cs @@ -6,7 +6,7 @@ using Microsoft.EntityFrameworkCore.Migrations; namespace GerbilManagerWebAPI.Migrations { /// - public partial class InitialCreate : Migration + public partial class initialCreate : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) @@ -16,7 +16,7 @@ namespace GerbilManagerWebAPI.Migrations columns: table => new { Id = table.Column(type: "uniqueidentifier", nullable: false), - Name = table.Column(type: "nvarchar(max)", nullable: true) + Name = table.Column(type: "nvarchar(max)", nullable: false) }, constraints: table => { @@ -28,8 +28,8 @@ namespace GerbilManagerWebAPI.Migrations columns: table => new { Id = table.Column(type: "uniqueidentifier", nullable: false), - Name = table.Column(type: "nvarchar(max)", nullable: true), - Gender = table.Column(type: "nvarchar(max)", nullable: false), + Name = table.Column(type: "nvarchar(max)", nullable: false), + Gender = table.Column(type: "nvarchar(max)", nullable: false), LitterId = table.Column(type: "uniqueidentifier", nullable: true), BreederId = table.Column(type: "uniqueidentifier", nullable: true) }, @@ -48,9 +48,9 @@ namespace GerbilManagerWebAPI.Migrations columns: table => new { Id = table.Column(type: "uniqueidentifier", nullable: false), - Name = table.Column(type: "nvarchar(max)", nullable: true), + Name = table.Column(type: "nvarchar(max)", nullable: false), Date = table.Column(type: "datetime2", nullable: false), - Strength = table.Column(type: "int", nullable: false), + Strength = table.Column(type: "int", nullable: true), FatherId = table.Column(type: "uniqueidentifier", nullable: true), MotherId = table.Column(type: "uniqueidentifier", nullable: true) }, diff --git a/GerbilManagerWebAPI/Migrations/ApplicationContextModelSnapshot.cs b/GerbilManagerWebAPI/Migrations/ApplicationContextModelSnapshot.cs index 5ff95f5..8e1d3bc 100644 --- a/GerbilManagerWebAPI/Migrations/ApplicationContextModelSnapshot.cs +++ b/GerbilManagerWebAPI/Migrations/ApplicationContextModelSnapshot.cs @@ -28,11 +28,12 @@ namespace GerbilManagerWebAPI.Migrations .HasColumnType("uniqueidentifier"); b.Property("Name") + .IsRequired() .HasColumnType("nvarchar(max)"); b.HasKey("Id"); - b.ToTable("Breeders"); + b.ToTable("Breeders", (string)null); }); modelBuilder.Entity("GerbilManagerWebAPI.Models.Gerbil", b => @@ -44,13 +45,15 @@ namespace GerbilManagerWebAPI.Migrations b.Property("BreederId") .HasColumnType("uniqueidentifier"); - b.Property("Gender") - .HasColumnType("int"); + b.Property("Gender") + .IsRequired() + .HasColumnType("nvarchar(max)"); b.Property("LitterId") .HasColumnType("uniqueidentifier"); b.Property("Name") + .IsRequired() .HasColumnType("nvarchar(max)"); b.HasKey("Id"); @@ -59,7 +62,7 @@ namespace GerbilManagerWebAPI.Migrations b.HasIndex("LitterId"); - b.ToTable("Gerbils"); + b.ToTable("Gerbils", (string)null); }); modelBuilder.Entity("GerbilManagerWebAPI.Models.Litter", b => @@ -78,9 +81,10 @@ namespace GerbilManagerWebAPI.Migrations .HasColumnType("uniqueidentifier"); b.Property("Name") + .IsRequired() .HasColumnType("nvarchar(max)"); - b.Property("Strength") + b.Property("Strength") .HasColumnType("int"); b.HasKey("Id"); @@ -89,7 +93,7 @@ namespace GerbilManagerWebAPI.Migrations b.HasIndex("MotherId"); - b.ToTable("Litters"); + b.ToTable("Litters", (string)null); }); modelBuilder.Entity("GerbilManagerWebAPI.Models.Gerbil", b =>