From 95cacc99e121019f5f6eb28cfba98dd9b04d8adb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Tue, 22 Dec 2020 16:41:21 +0300 Subject: [PATCH] Implemented CRUD ops. --- .../Controllers/BookController.cs | 59 ++++++++++++++++++- .../Dtos/CreateUpdateBookDto.cs | 11 ++++ 2 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 test/AbpPerfTest/AbpPerfTest.WithoutAbp/Dtos/CreateUpdateBookDto.cs diff --git a/test/AbpPerfTest/AbpPerfTest.WithoutAbp/Controllers/BookController.cs b/test/AbpPerfTest/AbpPerfTest.WithoutAbp/Controllers/BookController.cs index 2cb5d69164..96cb30eedd 100644 --- a/test/AbpPerfTest/AbpPerfTest.WithoutAbp/Controllers/BookController.cs +++ b/test/AbpPerfTest/AbpPerfTest.WithoutAbp/Controllers/BookController.cs @@ -1,7 +1,9 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using AbpPerfTest.WithoutAbp.Dtos; +using AbpPerfTest.WithoutAbp.Entities; using AbpPerfTest.WithoutAbp.EntityFramework; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; @@ -33,5 +35,60 @@ namespace AbpPerfTest.WithoutAbp.Controllers }) .ToList(); } + + [HttpGet] + [Route("{id}")] + public async Task GetAsync(Guid id) + { + var book = await _bookDbContext.Books.SingleAsync(b => b.Id == id); + + return new BookDto + { + Id = book.Id, + Name = book.Name, + Price = book.Price, + IsAvailable = book.IsAvailable + }; + } + + [HttpPost] + public async Task CreateAsync(CreateUpdateBookDto input) + { + var book = new Book + { + Id = Guid.NewGuid(), + Name = input.Name, + Price = input.Price, + IsAvailable = input.IsAvailable + }; + + await _bookDbContext.Books.AddAsync(book); + await _bookDbContext.SaveChangesAsync(); + + return book.Id; + } + + [HttpPut] + [Route("{id}")] + public async Task UpdateAsync(Guid id, CreateUpdateBookDto input) + { + var book = await _bookDbContext.Books.SingleAsync(b => b.Id == id); + + book.Name = input.Name; + book.Price = input.Price; + book.IsAvailable = input.IsAvailable; + + await _bookDbContext.SaveChangesAsync(); + } + + [HttpDelete] + [Route("{id}")] + public async Task DeleteAsync(Guid id) + { + var book = await _bookDbContext.Books.SingleAsync(b => b.Id == id); + + _bookDbContext.Books.Remove(book); + await _bookDbContext.SaveChangesAsync(); + } } } diff --git a/test/AbpPerfTest/AbpPerfTest.WithoutAbp/Dtos/CreateUpdateBookDto.cs b/test/AbpPerfTest/AbpPerfTest.WithoutAbp/Dtos/CreateUpdateBookDto.cs new file mode 100644 index 0000000000..f5af124a65 --- /dev/null +++ b/test/AbpPerfTest/AbpPerfTest.WithoutAbp/Dtos/CreateUpdateBookDto.cs @@ -0,0 +1,11 @@ +namespace AbpPerfTest.WithoutAbp.Dtos +{ + public class CreateUpdateBookDto + { + public string Name { get; set; } + + public float Price { get; set; } + + public bool IsAvailable { get; set; } + } +}