Browse Source

Implemented CRUD ops.

pull/6762/head
Halil İbrahim Kalkan 5 years ago
parent
commit
95cacc99e1
  1. 59
      test/AbpPerfTest/AbpPerfTest.WithoutAbp/Controllers/BookController.cs
  2. 11
      test/AbpPerfTest/AbpPerfTest.WithoutAbp/Dtos/CreateUpdateBookDto.cs

59
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<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();
}
}
}

11
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; }
}
}
Loading…
Cancel
Save