Create the Book entity in Flowfy.Domain like below;
using Flowfy.Entities;
using System;
namespace Flowfy.Book
{
public class Book : EntityBase<Guid>
{
public string Name { get; set; }
public decimal Price { get; set; }
}
}
Create the BookModel (BookDto) inside of Flowfy.Application.Contracts
using Flowfy.Dtos;
using System;
namespace Flowfy.Book
{
public class BookModel : ModelBase<Guid>
{
public string Name { get; set; }
public decimal Price { get; set; }
}
}
Create the BookService/ Book API in Flowfy.Application like below;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Volo.Abp.Domain.Repositories;
namespace Flowfy.Book
{
public class BookService : FlowfyAppService
{
private readonly IRepository<Book, Guid> BookRepository;
public BookService(
IRepository<Book, Guid> bookRepository)
{
BookRepository = bookRepository;
}
public async Task<List<BookModel>> GetAllAsync()
{
var books = (await BookRepository.GetListAsync()).ToList();
return ObjectMapper.Map<List<Book>, List<BookModel>>(books);
}
}
}
Auto map the Book entity and BookMode Dto in FlowfyApplicationAutoMapperProfile.cs file.
CreateMap<Flowfy.Book.Book, BookModel>();
Add Books to FlowfyDbContext.cs under the Flowfy.EntityFrameworkCore/EntityFrameworkCore as below;
public DbSet<Flowfy.Book.Book> Books { get; set; }
Configure the Books table in FlowfyDbContext.cs under the Flowfy.EntityFrameworkCore/EntityFrameworkCore as below;
builder.Entity<Flowfy.Book.Book>(b =>
{
b.ToTable(FlowfyConsts.DbTablePrefix + "Books", FlowfyConsts.DbSchema);
b.ConfigureByConvention();
b.Property(x => x.Name).HasMaxLength(128).IsRequired();
b.Property(x => x.Price).IsRequired();
});
Right clict the Flowfy.DbMigrator and Set as Startup Project then open the Package Manager Console and select Flowfy.EntityFrameworkCore project as Default project then write "add-migration MyBookTable" to migration.
Execute the generated migration
Run the Flowfy.DbMigrator console project to create Book table in database.
After running, refresh the database table, you will see Books table
Lastly, right click the Flowfy.HttpApi.Host and Set as Startup Project then Start without Debugging
Here is the your Book API.
Now we can call this api from client side.