This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
services.AddEntityFrameworkNpgsql() | |
.AddDbContext<DatabaseContext>() | |
.BuildServiceProvider(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private readonly DatabaseContext _db; | |
public ServiceController(DatabaseContext context) | |
{ | |
_db = context; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[HttpGet("{id}")] | |
public async Task<ActionResult<BookInfoDto>> GetBook(int id) | |
{ | |
BookInfoDto book = await _db.Books | |
.Select(x => new BookInfoDto() { BookID = x.BookID, Name = x.Name, AuthorName = x.Author.Name }) | |
.SingleOrDefaultAsync(x => x.BookID == id); | |
if (book == null) | |
return NotFound("İstenilen kitap bulunamadı"); | |
return Ok(book); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[HttpGet] | |
public async Task<IActionResult> GetBooks() | |
{ | |
List<BookInfoDto> books = await _db.Books | |
.Select(x => new BookInfoDto() { BookID = x.BookID, Name = x.Name, AuthorName = x.Author.Name }) | |
.ToListAsync(); | |
if (books.Count() == 0) | |
return NotFound(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Threading.Tasks; | |
using CoreAPI.DTOs; | |
using CoreAPI.Models; | |
using Microsoft.AspNetCore.Mvc; | |
using Microsoft.EntityFrameworkCore; | |
namespace CoreAPI.Controllers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Threading.Tasks; | |
using Microsoft.AspNetCore.Mvc; | |
namespace CoreAPI.Controllers | |
{ | |
[Route("[controller]/[action]")] | |
public class HomeController : Controller |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>.NET Core Web API</title> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> | |
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous"> | |
</head> | |
<body> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="container" style="margin-top:50px;"> | |
<div class="row"> | |
<div class="col-md-4"> | |
<button class="btn btn-success" id="kitaplariGetir">Kitapları Getir</button> | |
</div> | |
<div class="col-md-8"> | |
<div id="getBooksArea"> | |
<ul id="getBooks"></ul> | |
</div> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$("#kitaplariGetir").click(function(){ | |
$.ajax({ | |
type: 'GET', | |
url: '/api/Service/GetBooks', | |
success: function(books){ | |
$("#getBooks").html(""); | |
$.each(books, function(index, value){ | |
$("#getBooks").append("<li>Kitap Adı: <b>"+value.name+" - Yazarı: <b>"+value.authorName+"</b>"); | |
}); | |
} |