From 894159bc7fc9e4bc3bb5c67047416d69bdb253f8 Mon Sep 17 00:00:00 2001 From: BoluwatifeO Date: Wed, 22 Mar 2023 10:37:34 +0100 Subject: [PATCH] updates --- .../LibraryManagement/LibraryManagement.sln | 25 +++ .../Controllers/AuthorController.cs | 70 ++++++++ .../Controllers/BookController.cs | 69 ++++++++ .../Controllers/PublisherController.cs | 69 ++++++++ .../LibraryManagement/Data/AppDbContext.cs | 30 ++++ .../LibraryManagement.csproj | 22 +++ .../20230320103709_InitialCreate.Designer.cs | 160 ++++++++++++++++++ .../20230320103709_InitialCreate.cs | 116 +++++++++++++ .../Migrations/AppDbContextModelSnapshot.cs | 158 +++++++++++++++++ .../LibraryManagement/Models/Author.cs | 20 +++ .../LibraryManagement/Models/Book.cs | 16 ++ .../LibraryManagement/Models/Book_Author.cs | 12 ++ .../LibraryManagement/Models/Publisher.cs | 18 ++ .../LibraryManagement/Program.cs | 32 ++++ .../Properties/launchSettings.json | 31 ++++ .../LibraryManagement/WeatherForecast.cs | 13 ++ .../appsettings.Development.json | 8 + .../LibraryManagement/appsettings.json | 12 ++ 18 files changed, 881 insertions(+) create mode 100644 Boluwatife/StageThreeTask/LibraryManagement/LibraryManagement.sln create mode 100644 Boluwatife/StageThreeTask/LibraryManagement/LibraryManagement/Controllers/AuthorController.cs create mode 100644 Boluwatife/StageThreeTask/LibraryManagement/LibraryManagement/Controllers/BookController.cs create mode 100644 Boluwatife/StageThreeTask/LibraryManagement/LibraryManagement/Controllers/PublisherController.cs create mode 100644 Boluwatife/StageThreeTask/LibraryManagement/LibraryManagement/Data/AppDbContext.cs create mode 100644 Boluwatife/StageThreeTask/LibraryManagement/LibraryManagement/LibraryManagement.csproj create mode 100644 Boluwatife/StageThreeTask/LibraryManagement/LibraryManagement/Migrations/20230320103709_InitialCreate.Designer.cs create mode 100644 Boluwatife/StageThreeTask/LibraryManagement/LibraryManagement/Migrations/20230320103709_InitialCreate.cs create mode 100644 Boluwatife/StageThreeTask/LibraryManagement/LibraryManagement/Migrations/AppDbContextModelSnapshot.cs create mode 100644 Boluwatife/StageThreeTask/LibraryManagement/LibraryManagement/Models/Author.cs create mode 100644 Boluwatife/StageThreeTask/LibraryManagement/LibraryManagement/Models/Book.cs create mode 100644 Boluwatife/StageThreeTask/LibraryManagement/LibraryManagement/Models/Book_Author.cs create mode 100644 Boluwatife/StageThreeTask/LibraryManagement/LibraryManagement/Models/Publisher.cs create mode 100644 Boluwatife/StageThreeTask/LibraryManagement/LibraryManagement/Program.cs create mode 100644 Boluwatife/StageThreeTask/LibraryManagement/LibraryManagement/Properties/launchSettings.json create mode 100644 Boluwatife/StageThreeTask/LibraryManagement/LibraryManagement/WeatherForecast.cs create mode 100644 Boluwatife/StageThreeTask/LibraryManagement/LibraryManagement/appsettings.Development.json create mode 100644 Boluwatife/StageThreeTask/LibraryManagement/LibraryManagement/appsettings.json diff --git a/Boluwatife/StageThreeTask/LibraryManagement/LibraryManagement.sln b/Boluwatife/StageThreeTask/LibraryManagement/LibraryManagement.sln new file mode 100644 index 0000000..6ef7f53 --- /dev/null +++ b/Boluwatife/StageThreeTask/LibraryManagement/LibraryManagement.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.2.32630.192 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LibraryManagement", "LibraryManagement\LibraryManagement.csproj", "{5018D2E0-88CE-44B4-8664-204E32183ED9}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {5018D2E0-88CE-44B4-8664-204E32183ED9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5018D2E0-88CE-44B4-8664-204E32183ED9}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5018D2E0-88CE-44B4-8664-204E32183ED9}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5018D2E0-88CE-44B4-8664-204E32183ED9}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {B82C9022-4DDD-4721-8D27-A05D0D7251BE} + EndGlobalSection +EndGlobal diff --git a/Boluwatife/StageThreeTask/LibraryManagement/LibraryManagement/Controllers/AuthorController.cs b/Boluwatife/StageThreeTask/LibraryManagement/LibraryManagement/Controllers/AuthorController.cs new file mode 100644 index 0000000..1903239 --- /dev/null +++ b/Boluwatife/StageThreeTask/LibraryManagement/LibraryManagement/Controllers/AuthorController.cs @@ -0,0 +1,70 @@ +using LibraryManagement.Data; +using LibraryManagement.Models; +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; + +namespace LibraryManagement.Controllers +{ + [Route("api/[controller]")] + [ApiController] + public class AuthorController : ControllerBase + { + private readonly AppDbContext _context; + + public AuthorController(AppDbContext context) + { + _context = context; + } + [HttpGet] + public async Task> Get() + { + return await _context.Authors.ToListAsync(); + } + + [HttpGet("{id}")] + public async Task Get(int id) + { + var author = await _context.Authors.FirstOrDefaultAsync(m => m.AuthorId == id); + if (author == null) + return NotFound(); + return Ok(author); + + } + + [HttpPost] + public async Task Post(Author author) + { + _context.Add(author); + await _context.SaveChangesAsync(); + return Ok(); + } + + [HttpPut] + public async Task Put(Author authorData) + { + if (authorData == null || authorData.AuthorId == 0) + return BadRequest(); + + var author = await _context.Authors.FindAsync(authorData.AuthorId); + if (author == null) + return NotFound(); + author.Name = authorData.Name; + author.PublisherId = authorData.PublisherId; + author.Publisher = authorData.Publisher; + author.Book_Authors = authorData.Book_Authors; + await _context.SaveChangesAsync(); + return Ok(); + } + + [HttpDelete("{id}")] + public async Task Delete(int id) + { + var author = await _context.Authors.FindAsync(id); + if (author == null) return NotFound(); + _context.Authors.Remove(author); + await _context.SaveChangesAsync(); + return Ok(); + + } + } +} diff --git a/Boluwatife/StageThreeTask/LibraryManagement/LibraryManagement/Controllers/BookController.cs b/Boluwatife/StageThreeTask/LibraryManagement/LibraryManagement/Controllers/BookController.cs new file mode 100644 index 0000000..50661d0 --- /dev/null +++ b/Boluwatife/StageThreeTask/LibraryManagement/LibraryManagement/Controllers/BookController.cs @@ -0,0 +1,69 @@ +using LibraryManagement.Data; +using LibraryManagement.Models; +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; + +namespace LibraryManagement.Controllers +{ + [Route("api/[controller]")] + [ApiController] + public class BookController : ControllerBase + { + private readonly AppDbContext _context; + + public BookController(AppDbContext context) + { + _context = context; + } + [HttpGet] + public async Task> Get() + { + return await _context.Books.ToListAsync(); + } + + [HttpGet("{id}")] + public async Task Get(int id) + { + var book = await _context.Books.FirstOrDefaultAsync(m => m.BookId == id); + if (book == null) + return NotFound(); + return Ok(book); + + } + + [HttpPost] + public async Task Post(Book book) + { + _context.Add(book); + await _context.SaveChangesAsync(); + return Ok(); + } + + [HttpPut] + public async Task Put(Book bookData) + { + if (bookData == null || bookData.BookId == 0) + return BadRequest(); + + var book = await _context.Books.FindAsync(bookData.BookId); + if (book == null) + return NotFound(); + book.Title = bookData.Title; + book.Description = bookData.Description; + book.Book_Authors = bookData.Book_Authors; + await _context.SaveChangesAsync(); + return Ok(); + } + + [HttpDelete("{id}")] + public async Task Delete(int id) + { + var book = await _context.Books.FindAsync(id); + if (book == null) return NotFound(); + _context.Books.Remove(book); + await _context.SaveChangesAsync(); + return Ok(); + + } + } +} diff --git a/Boluwatife/StageThreeTask/LibraryManagement/LibraryManagement/Controllers/PublisherController.cs b/Boluwatife/StageThreeTask/LibraryManagement/LibraryManagement/Controllers/PublisherController.cs new file mode 100644 index 0000000..0b64100 --- /dev/null +++ b/Boluwatife/StageThreeTask/LibraryManagement/LibraryManagement/Controllers/PublisherController.cs @@ -0,0 +1,69 @@ +using LibraryManagement.Data; +using LibraryManagement.Models; +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; + +namespace LibraryManagement.Controllers +{ + [Route("api/[controller]")] + [ApiController] + public class PublisherController : ControllerBase + { + private readonly AppDbContext _context; + + public PublisherController(AppDbContext context) + { + _context = context; + } + [HttpGet] + public async Task> Get() + { + return await _context.Publishers.ToListAsync(); + } + + [HttpGet("{id}")] + public async Task Get(int id) + { + var publisher = await _context.Publishers.FirstOrDefaultAsync(m => m.PublisherId == id); + if (publisher == null) + return NotFound(); + return Ok(publisher); + + } + + [HttpPost] + public async Task Post(Publisher publisher) + { + _context.Add(publisher); + await _context.SaveChangesAsync(); + return Ok(); + } + + [HttpPut] + public async Task Put(Publisher publisherData) + { + if (publisherData == null || publisherData.PublisherId == 0) + return BadRequest(); + + var publisher = await _context.Publishers.FindAsync(publisherData.PublisherId); + if (publisher == null) + return NotFound(); + publisher.Name = publisherData.Name; + publisher.Address = publisherData.Address; + publisher.Authors = publisherData.Authors; + await _context.SaveChangesAsync(); + return Ok(); + } + + [HttpDelete("{id}")] + public async Task Delete(int id) + { + var publisher = await _context.Publishers.FindAsync(id); + if (publisher == null) return NotFound(); + _context.Publishers.Remove(publisher); + await _context.SaveChangesAsync(); + return Ok(); + + } + } +} diff --git a/Boluwatife/StageThreeTask/LibraryManagement/LibraryManagement/Data/AppDbContext.cs b/Boluwatife/StageThreeTask/LibraryManagement/LibraryManagement/Data/AppDbContext.cs new file mode 100644 index 0000000..5583e5e --- /dev/null +++ b/Boluwatife/StageThreeTask/LibraryManagement/LibraryManagement/Data/AppDbContext.cs @@ -0,0 +1,30 @@ +using LibraryManagement.Models; +using Microsoft.EntityFrameworkCore; + +namespace LibraryManagement.Data +{ + public class AppDbContext : DbContext + { + public AppDbContext(DbContextOptions options) : base(options) { } + + + + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + modelBuilder.Entity() + .HasOne(book => book.Book) + .WithMany(book_author => book_author.Book_Authors) + .HasForeignKey(book_id => book_id.BookId); + + modelBuilder.Entity() + .HasOne(author => author.Author) + .WithMany(book_author => book_author.Book_Authors) + .HasForeignKey(author_id => author_id.AuthorId); + } + + public DbSet Publishers { get; set; } + public DbSet Authors { get; set; } + public DbSet Books { get; set; } + public DbSet Book_Authors { get; set; } + } +} diff --git a/Boluwatife/StageThreeTask/LibraryManagement/LibraryManagement/LibraryManagement.csproj b/Boluwatife/StageThreeTask/LibraryManagement/LibraryManagement/LibraryManagement.csproj new file mode 100644 index 0000000..ccf2c51 --- /dev/null +++ b/Boluwatife/StageThreeTask/LibraryManagement/LibraryManagement/LibraryManagement.csproj @@ -0,0 +1,22 @@ + + + + net6.0 + enable + enable + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + diff --git a/Boluwatife/StageThreeTask/LibraryManagement/LibraryManagement/Migrations/20230320103709_InitialCreate.Designer.cs b/Boluwatife/StageThreeTask/LibraryManagement/LibraryManagement/Migrations/20230320103709_InitialCreate.Designer.cs new file mode 100644 index 0000000..1c53c73 --- /dev/null +++ b/Boluwatife/StageThreeTask/LibraryManagement/LibraryManagement/Migrations/20230320103709_InitialCreate.Designer.cs @@ -0,0 +1,160 @@ +// +using LibraryManagement.Data; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace LibraryManagement.Migrations +{ + [DbContext(typeof(AppDbContext))] + [Migration("20230320103709_InitialCreate")] + partial class InitialCreate + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "6.0.1") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 1L, 1); + + modelBuilder.Entity("LibraryManagement.Models.Author", b => + { + b.Property("AuthorId") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("AuthorId"), 1L, 1); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("PublisherId") + .HasColumnType("int"); + + b.HasKey("AuthorId"); + + b.HasIndex("PublisherId"); + + b.ToTable("Authors"); + }); + + modelBuilder.Entity("LibraryManagement.Models.Book", b => + { + b.Property("BookId") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("BookId"), 1L, 1); + + b.Property("Description") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Title") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("BookId"); + + b.ToTable("Books"); + }); + + modelBuilder.Entity("LibraryManagement.Models.Book_Author", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("AuthorId") + .HasColumnType("int"); + + b.Property("BookId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("AuthorId"); + + b.HasIndex("BookId"); + + b.ToTable("Book_Authors"); + }); + + modelBuilder.Entity("LibraryManagement.Models.Publisher", b => + { + b.Property("PublisherId") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("PublisherId"), 1L, 1); + + b.Property("Address") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("PublisherId"); + + b.ToTable("Publishers"); + }); + + modelBuilder.Entity("LibraryManagement.Models.Author", b => + { + b.HasOne("LibraryManagement.Models.Publisher", "Publisher") + .WithMany("Authors") + .HasForeignKey("PublisherId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Publisher"); + }); + + modelBuilder.Entity("LibraryManagement.Models.Book_Author", b => + { + b.HasOne("LibraryManagement.Models.Author", "Author") + .WithMany("Book_Authors") + .HasForeignKey("AuthorId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("LibraryManagement.Models.Book", "Book") + .WithMany("Book_Authors") + .HasForeignKey("BookId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Author"); + + b.Navigation("Book"); + }); + + modelBuilder.Entity("LibraryManagement.Models.Author", b => + { + b.Navigation("Book_Authors"); + }); + + modelBuilder.Entity("LibraryManagement.Models.Book", b => + { + b.Navigation("Book_Authors"); + }); + + modelBuilder.Entity("LibraryManagement.Models.Publisher", b => + { + b.Navigation("Authors"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Boluwatife/StageThreeTask/LibraryManagement/LibraryManagement/Migrations/20230320103709_InitialCreate.cs b/Boluwatife/StageThreeTask/LibraryManagement/LibraryManagement/Migrations/20230320103709_InitialCreate.cs new file mode 100644 index 0000000..a130e1f --- /dev/null +++ b/Boluwatife/StageThreeTask/LibraryManagement/LibraryManagement/Migrations/20230320103709_InitialCreate.cs @@ -0,0 +1,116 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace LibraryManagement.Migrations +{ + public partial class InitialCreate : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Books", + columns: table => new + { + BookId = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Title = table.Column(type: "nvarchar(max)", nullable: false), + Description = table.Column(type: "nvarchar(max)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Books", x => x.BookId); + }); + + migrationBuilder.CreateTable( + name: "Publishers", + columns: table => new + { + PublisherId = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Name = table.Column(type: "nvarchar(max)", nullable: false), + Address = table.Column(type: "nvarchar(max)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Publishers", x => x.PublisherId); + }); + + migrationBuilder.CreateTable( + name: "Authors", + columns: table => new + { + AuthorId = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Name = table.Column(type: "nvarchar(max)", nullable: false), + PublisherId = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Authors", x => x.AuthorId); + table.ForeignKey( + name: "FK_Authors_Publishers_PublisherId", + column: x => x.PublisherId, + principalTable: "Publishers", + principalColumn: "PublisherId", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Book_Authors", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + BookId = table.Column(type: "int", nullable: false), + AuthorId = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Book_Authors", x => x.Id); + table.ForeignKey( + name: "FK_Book_Authors_Authors_AuthorId", + column: x => x.AuthorId, + principalTable: "Authors", + principalColumn: "AuthorId", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_Book_Authors_Books_BookId", + column: x => x.BookId, + principalTable: "Books", + principalColumn: "BookId", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_Authors_PublisherId", + table: "Authors", + column: "PublisherId"); + + migrationBuilder.CreateIndex( + name: "IX_Book_Authors_AuthorId", + table: "Book_Authors", + column: "AuthorId"); + + migrationBuilder.CreateIndex( + name: "IX_Book_Authors_BookId", + table: "Book_Authors", + column: "BookId"); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Book_Authors"); + + migrationBuilder.DropTable( + name: "Authors"); + + migrationBuilder.DropTable( + name: "Books"); + + migrationBuilder.DropTable( + name: "Publishers"); + } + } +} diff --git a/Boluwatife/StageThreeTask/LibraryManagement/LibraryManagement/Migrations/AppDbContextModelSnapshot.cs b/Boluwatife/StageThreeTask/LibraryManagement/LibraryManagement/Migrations/AppDbContextModelSnapshot.cs new file mode 100644 index 0000000..029fd15 --- /dev/null +++ b/Boluwatife/StageThreeTask/LibraryManagement/LibraryManagement/Migrations/AppDbContextModelSnapshot.cs @@ -0,0 +1,158 @@ +// +using LibraryManagement.Data; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace LibraryManagement.Migrations +{ + [DbContext(typeof(AppDbContext))] + partial class AppDbContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "6.0.1") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 1L, 1); + + modelBuilder.Entity("LibraryManagement.Models.Author", b => + { + b.Property("AuthorId") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("AuthorId"), 1L, 1); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("PublisherId") + .HasColumnType("int"); + + b.HasKey("AuthorId"); + + b.HasIndex("PublisherId"); + + b.ToTable("Authors"); + }); + + modelBuilder.Entity("LibraryManagement.Models.Book", b => + { + b.Property("BookId") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("BookId"), 1L, 1); + + b.Property("Description") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Title") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("BookId"); + + b.ToTable("Books"); + }); + + modelBuilder.Entity("LibraryManagement.Models.Book_Author", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("AuthorId") + .HasColumnType("int"); + + b.Property("BookId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("AuthorId"); + + b.HasIndex("BookId"); + + b.ToTable("Book_Authors"); + }); + + modelBuilder.Entity("LibraryManagement.Models.Publisher", b => + { + b.Property("PublisherId") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("PublisherId"), 1L, 1); + + b.Property("Address") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("PublisherId"); + + b.ToTable("Publishers"); + }); + + modelBuilder.Entity("LibraryManagement.Models.Author", b => + { + b.HasOne("LibraryManagement.Models.Publisher", "Publisher") + .WithMany("Authors") + .HasForeignKey("PublisherId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Publisher"); + }); + + modelBuilder.Entity("LibraryManagement.Models.Book_Author", b => + { + b.HasOne("LibraryManagement.Models.Author", "Author") + .WithMany("Book_Authors") + .HasForeignKey("AuthorId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("LibraryManagement.Models.Book", "Book") + .WithMany("Book_Authors") + .HasForeignKey("BookId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Author"); + + b.Navigation("Book"); + }); + + modelBuilder.Entity("LibraryManagement.Models.Author", b => + { + b.Navigation("Book_Authors"); + }); + + modelBuilder.Entity("LibraryManagement.Models.Book", b => + { + b.Navigation("Book_Authors"); + }); + + modelBuilder.Entity("LibraryManagement.Models.Publisher", b => + { + b.Navigation("Authors"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Boluwatife/StageThreeTask/LibraryManagement/LibraryManagement/Models/Author.cs b/Boluwatife/StageThreeTask/LibraryManagement/LibraryManagement/Models/Author.cs new file mode 100644 index 0000000..fbb9247 --- /dev/null +++ b/Boluwatife/StageThreeTask/LibraryManagement/LibraryManagement/Models/Author.cs @@ -0,0 +1,20 @@ +using System.ComponentModel.DataAnnotations; + +namespace LibraryManagement.Models +{ + public class Author + { + [Key] + public int AuthorId { get; set; } + [Required] + public string Name { get; set; } + + public List Book_Authors { get; set; } + + public int PublisherId { get; set; } + + public Publisher Publisher { get; set; } + + + } +} diff --git a/Boluwatife/StageThreeTask/LibraryManagement/LibraryManagement/Models/Book.cs b/Boluwatife/StageThreeTask/LibraryManagement/LibraryManagement/Models/Book.cs new file mode 100644 index 0000000..b3d29b0 --- /dev/null +++ b/Boluwatife/StageThreeTask/LibraryManagement/LibraryManagement/Models/Book.cs @@ -0,0 +1,16 @@ +using System.ComponentModel.DataAnnotations; + +namespace LibraryManagement.Models +{ + public class Book + { + [Key] + public int BookId { get; set; } + + public string Title { get; set; } + + public string Description { get; set; } + + public List Book_Authors { get; set; } + } +} diff --git a/Boluwatife/StageThreeTask/LibraryManagement/LibraryManagement/Models/Book_Author.cs b/Boluwatife/StageThreeTask/LibraryManagement/LibraryManagement/Models/Book_Author.cs new file mode 100644 index 0000000..a7b193f --- /dev/null +++ b/Boluwatife/StageThreeTask/LibraryManagement/LibraryManagement/Models/Book_Author.cs @@ -0,0 +1,12 @@ +namespace LibraryManagement.Models +{ + public class Book_Author + { + public int Id { get; set; } + public int BookId { get; set; } + public Book Book { get; set; } + + public int AuthorId { get; set; } + public Author Author { get; set; } + } +} diff --git a/Boluwatife/StageThreeTask/LibraryManagement/LibraryManagement/Models/Publisher.cs b/Boluwatife/StageThreeTask/LibraryManagement/LibraryManagement/Models/Publisher.cs new file mode 100644 index 0000000..d95191d --- /dev/null +++ b/Boluwatife/StageThreeTask/LibraryManagement/LibraryManagement/Models/Publisher.cs @@ -0,0 +1,18 @@ +using System.ComponentModel.DataAnnotations; + +namespace LibraryManagement.Models +{ + public class Publisher + { + [Key] + public int PublisherId { get; set; } + + [Required] + public string Name { get; set; } + + [Required] + public string Address { get; set; } + + public List Authors { get; set; } + } +} diff --git a/Boluwatife/StageThreeTask/LibraryManagement/LibraryManagement/Program.cs b/Boluwatife/StageThreeTask/LibraryManagement/LibraryManagement/Program.cs new file mode 100644 index 0000000..a662ff6 --- /dev/null +++ b/Boluwatife/StageThreeTask/LibraryManagement/LibraryManagement/Program.cs @@ -0,0 +1,32 @@ +using LibraryManagement.Data; +using Microsoft.EntityFrameworkCore; + +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(options => +{ + options.UseSqlServer(builder.Configuration.GetConnectionString("DefaultConnection")); +}); + +var app = builder.Build(); + +// Configure the HTTP request pipeline. +if (app.Environment.IsDevelopment()) +{ + app.UseSwagger(); + app.UseSwaggerUI(); +} + +app.UseHttpsRedirection(); + +app.UseAuthorization(); + +app.MapControllers(); + +app.Run(); diff --git a/Boluwatife/StageThreeTask/LibraryManagement/LibraryManagement/Properties/launchSettings.json b/Boluwatife/StageThreeTask/LibraryManagement/LibraryManagement/Properties/launchSettings.json new file mode 100644 index 0000000..0dad0a4 --- /dev/null +++ b/Boluwatife/StageThreeTask/LibraryManagement/LibraryManagement/Properties/launchSettings.json @@ -0,0 +1,31 @@ +{ + "$schema": "https://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:49641", + "sslPort": 44374 + } + }, + "profiles": { + "LibraryManagement": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "https://localhost:7226;http://localhost:5226", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/Boluwatife/StageThreeTask/LibraryManagement/LibraryManagement/WeatherForecast.cs b/Boluwatife/StageThreeTask/LibraryManagement/LibraryManagement/WeatherForecast.cs new file mode 100644 index 0000000..3ec972f --- /dev/null +++ b/Boluwatife/StageThreeTask/LibraryManagement/LibraryManagement/WeatherForecast.cs @@ -0,0 +1,13 @@ +namespace LibraryManagement +{ + public class WeatherForecast + { + public DateTime Date { get; set; } + + public int TemperatureC { get; set; } + + public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); + + public string? Summary { get; set; } + } +} \ No newline at end of file diff --git a/Boluwatife/StageThreeTask/LibraryManagement/LibraryManagement/appsettings.Development.json b/Boluwatife/StageThreeTask/LibraryManagement/LibraryManagement/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/Boluwatife/StageThreeTask/LibraryManagement/LibraryManagement/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/Boluwatife/StageThreeTask/LibraryManagement/LibraryManagement/appsettings.json b/Boluwatife/StageThreeTask/LibraryManagement/LibraryManagement/appsettings.json new file mode 100644 index 0000000..a34ac62 --- /dev/null +++ b/Boluwatife/StageThreeTask/LibraryManagement/LibraryManagement/appsettings.json @@ -0,0 +1,12 @@ +{ + "ConnectionStrings": { + "DefaultConnection": "Data Source=DESKTOP-8FNTR0C;Initial Catalog=LibraryManagement;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False" + }, + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +}