|
|
|
@ -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<BookDto> 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<Guid> 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(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|