Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions Boluwatife/StageThreeTask/LibraryManagement/LibraryManagement.sln
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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<IEnumerable<Author>> Get()
{
return await _context.Authors.ToListAsync();
}

[HttpGet("{id}")]
public async Task<IActionResult> 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<IActionResult> Post(Author author)
{
_context.Add(author);
await _context.SaveChangesAsync();
return Ok();
}

[HttpPut]
public async Task<IActionResult> 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<IActionResult> Delete(int id)
{
var author = await _context.Authors.FindAsync(id);
if (author == null) return NotFound();
_context.Authors.Remove(author);
await _context.SaveChangesAsync();
return Ok();

}
}
}
Original file line number Diff line number Diff line change
@@ -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<IEnumerable<Book>> Get()
{
return await _context.Books.ToListAsync();
}

[HttpGet("{id}")]
public async Task<IActionResult> 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<IActionResult> Post(Book book)
{
_context.Add(book);
await _context.SaveChangesAsync();
return Ok();
}

[HttpPut]
public async Task<IActionResult> 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<IActionResult> Delete(int id)
{
var book = await _context.Books.FindAsync(id);
if (book == null) return NotFound();
_context.Books.Remove(book);
await _context.SaveChangesAsync();
return Ok();

}
}
}
Original file line number Diff line number Diff line change
@@ -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<IEnumerable<Publisher>> Get()
{
return await _context.Publishers.ToListAsync();
}

[HttpGet("{id}")]
public async Task<IActionResult> 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<IActionResult> Post(Publisher publisher)
{
_context.Add(publisher);
await _context.SaveChangesAsync();
return Ok();
}

[HttpPut]
public async Task<IActionResult> 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<IActionResult> Delete(int id)
{
var publisher = await _context.Publishers.FindAsync(id);
if (publisher == null) return NotFound();
_context.Publishers.Remove(publisher);
await _context.SaveChangesAsync();
return Ok();

}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using LibraryManagement.Models;
using Microsoft.EntityFrameworkCore;

namespace LibraryManagement.Data
{
public class AppDbContext : DbContext
{
public AppDbContext(DbContextOptions<AppDbContext> options) : base(options) { }



protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Book_Author>()
.HasOne(book => book.Book)
.WithMany(book_author => book_author.Book_Authors)
.HasForeignKey(book_id => book_id.BookId);

modelBuilder.Entity<Book_Author>()
.HasOne(author => author.Author)
.WithMany(book_author => book_author.Book_Authors)
.HasForeignKey(author_id => author_id.AuthorId);
}

public DbSet<Publisher> Publishers { get; set; }
public DbSet<Author> Authors { get; set; }
public DbSet<Book> Books { get; set; }
public DbSet<Book_Author> Book_Authors { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
</ItemGroup>

</Project>
Loading